Skip to content

Commit

Permalink
fix: access qualified aliases from lookup (#531)
Browse files Browse the repository at this point in the history
* add test case

This adds a test case illustrating the issue.  The next step is to fix
it!

* fix point at which aliases are initialised

Simply put, aliases were being initialised at the wrong point and this
was causing them to be missed.
  • Loading branch information
DavePearce authored Jan 10, 2025
1 parent 77b454d commit 34403f6
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 31 deletions.
53 changes: 22 additions & 31 deletions pkg/corset/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,6 @@ func (r *resolver) initialiseDeclarations(scope *ModuleScope, circuit *Circuit)
return errs
}

// Process all assignment column declarations. These are more complex than for
// input columns, since there can be dependencies between them. Thus, we cannot
// simply resolve them in one linear scan.
func (r *resolver) resolveDeclarations(scope *ModuleScope, circuit *Circuit) []SyntaxError {
// Input columns must be allocated before assignemts, since the hir.Schema
// separates these out.
errs := r.resolveDeclarationsInModule(scope, circuit.Declarations)
//
for _, m := range circuit.Modules {
// Process all declarations in the module
merrs := r.resolveDeclarationsInModule(scope.Enter(m.Name), m.Declarations)
// Package up all errors
errs = append(errs, merrs...)
}
//
return errs
}

// Resolve all columns declared in a given module. This is tricky because
// assignments can depend on the declaration of other columns. Hence, we have
// to process all columns before we can sure that they are all declared
// correctly.
func (r *resolver) resolveDeclarationsInModule(scope *ModuleScope, decls []Declaration) []SyntaxError {
// Aliases
if errors := r.initialiseAliasesInModule(scope, decls); len(errors) > 0 {
return errors
}
// Finalise everything
return r.finaliseDeclarationsInModule(scope, decls)
}

// Initialise all declarations in the given module scope. That means allocating
// all bindings into the scope, whilst also ensuring that we never have two
// bindings for the same symbol, etc. The key is that, at this stage, all
Expand Down Expand Up @@ -124,6 +93,10 @@ func (r *resolver) initialiseDeclarationsInModule(scope *ModuleScope, decls []De
}
}
}
// Third, intialise aliases
if errors := r.initialiseAliasesInModule(scope, decls); len(errors) > 0 {
return errors
}
//
return errors
}
Expand Down Expand Up @@ -179,6 +152,24 @@ func (r *resolver) initialiseAliasesInModule(scope *ModuleScope, decls []Declara
return errors
}

// Process all assignment column declarations. These are more complex than for
// input columns, since there can be dependencies between them. Thus, we cannot
// simply resolve them in one linear scan.
func (r *resolver) resolveDeclarations(scope *ModuleScope, circuit *Circuit) []SyntaxError {
// Input columns must be allocated before assignemts, since the hir.Schema
// separates these out.
errs := r.finaliseDeclarationsInModule(scope, circuit.Declarations)
//
for _, m := range circuit.Modules {
// Process all declarations in the module
merrs := r.finaliseDeclarationsInModule(scope.Enter(m.Name), m.Declarations)
// Package up all errors
errs = append(errs, merrs...)
}
//
return errs
}

// Finalise all declarations given in a module. This requires an iterative
// process as we cannot finalise a declaration until all of its dependencies
// have been themselves finalised. For example, a function which depends upon
Expand Down
4 changes: 4 additions & 0 deletions pkg/test/valid_corset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ func Test_Lookup_10(t *testing.T) {
Check(t, false, "lookup_10")
}

func Test_Lookup_11(t *testing.T) {
Check(t, false, "lookup_11")
}

// ===================================================================
// Interleaving
// ===================================================================
Expand Down
175 changes: 175 additions & 0 deletions testdata/lookup_11.accepts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
;; { "m1.X": [], "m1.Y": [] }
;; { "m1.X": [0], "m1.Y": [0] }
;; Check initial padding row!
{ "m1.X": [0], "m1.Y": [1] }
;;
{ "m1.X": [0,0], "m1.Y": [0,0] }
{ "m1.X": [0,0], "m1.Y": [0,1] }
{ "m1.X": [0,0], "m1.Y": [1,0] }
{ "m1.X": [1,0], "m1.Y": [0,1] }
{ "m1.X": [1,0], "m1.Y": [1,0] }
{ "m1.X": [1,0], "m1.Y": [1,1] }
{ "m1.X": [0,1], "m1.Y": [0,1] }
{ "m1.X": [0,1], "m1.Y": [1,0] }
{ "m1.X": [0,1], "m1.Y": [1,1] }
{ "m1.X": [1,1], "m1.Y": [0,1] }
{ "m1.X": [1,1], "m1.Y": [1,0] }
{ "m1.X": [1,1], "m1.Y": [1,1] }
{ "m1.X": [1,1], "m1.Y": [1,2] }
{ "m1.X": [2,2], "m1.Y": [2,2] }
{ "m1.X": [2,2], "m1.Y": [2,1] }
{ "m1.X": [2,2], "m1.Y": [1,2] }
{ "m1.X": [1,2], "m1.Y": [2,1] }
{ "m1.X": [1,2], "m1.Y": [1,2] }
{ "m1.X": [2,1], "m1.Y": [2,1] }
{ "m1.X": [2,1], "m1.Y": [1,2] }
{ "m1.X": [1,1], "m1.Y": [2,1] }
{ "m1.X": [1,1], "m1.Y": [1,2] }
{ "m1.X": [1,1], "m1.Y": [1,1] }
;;
{ "m1.X": [0,0,0], "m1.Y": [2,0,1] }
{ "m1.X": [1,0,0], "m1.Y": [2,0,1] }
{ "m1.X": [0,1,0], "m1.Y": [2,0,1] }
{ "m1.X": [0,0,1], "m1.Y": [2,0,1] }
{ "m1.X": [1,0,1], "m1.Y": [2,0,1] }
{ "m1.X": [0,1,1], "m1.Y": [2,0,1] }
{ "m1.X": [1,1,0], "m1.Y": [2,0,1] }
{ "m1.X": [1,1,1], "m1.Y": [2,0,1] }
{ "m1.X": [0,0,0], "m1.Y": [0,2,1] }
{ "m1.X": [1,0,0], "m1.Y": [0,2,1] }
{ "m1.X": [0,1,0], "m1.Y": [0,2,1] }
{ "m1.X": [0,0,1], "m1.Y": [0,2,1] }
{ "m1.X": [1,0,1], "m1.Y": [0,2,1] }
{ "m1.X": [0,1,1], "m1.Y": [0,2,1] }
{ "m1.X": [1,1,0], "m1.Y": [0,2,1] }
{ "m1.X": [1,1,1], "m1.Y": [0,2,1] }
{ "m1.X": [0,0,0], "m1.Y": [0,1,2] }
{ "m1.X": [1,0,0], "m1.Y": [0,1,2] }
{ "m1.X": [0,1,0], "m1.Y": [0,1,2] }
{ "m1.X": [0,0,1], "m1.Y": [0,1,2] }
{ "m1.X": [1,0,1], "m1.Y": [0,1,2] }
{ "m1.X": [0,1,1], "m1.Y": [0,1,2] }
{ "m1.X": [1,1,0], "m1.Y": [0,1,2] }
{ "m1.X": [1,1,1], "m1.Y": [0,1,2] }
{ "m1.X": [0,0,0], "m1.Y": [2,1,0] }
{ "m1.X": [1,0,0], "m1.Y": [2,1,0] }
{ "m1.X": [0,1,0], "m1.Y": [2,1,0] }
{ "m1.X": [0,0,1], "m1.Y": [2,1,0] }
{ "m1.X": [1,0,1], "m1.Y": [2,1,0] }
{ "m1.X": [0,1,1], "m1.Y": [2,1,0] }
{ "m1.X": [1,1,0], "m1.Y": [2,1,0] }
{ "m1.X": [1,1,1], "m1.Y": [2,1,0] }
{ "m1.X": [0,0,0], "m1.Y": [1,2,0] }
{ "m1.X": [1,0,0], "m1.Y": [1,2,0] }
{ "m1.X": [0,1,0], "m1.Y": [1,2,0] }
{ "m1.X": [0,0,1], "m1.Y": [1,2,0] }
{ "m1.X": [1,0,1], "m1.Y": [1,2,0] }
{ "m1.X": [0,1,1], "m1.Y": [1,2,0] }
{ "m1.X": [1,1,0], "m1.Y": [1,2,0] }
{ "m1.X": [1,1,1], "m1.Y": [1,2,0] }
{ "m1.X": [0,0,0], "m1.Y": [1,0,2] }
{ "m1.X": [1,0,0], "m1.Y": [1,0,2] }
{ "m1.X": [0,1,0], "m1.Y": [1,0,2] }
{ "m1.X": [0,0,1], "m1.Y": [1,0,2] }
{ "m1.X": [1,0,1], "m1.Y": [1,0,2] }
{ "m1.X": [0,1,1], "m1.Y": [1,0,2] }
{ "m1.X": [1,1,0], "m1.Y": [1,0,2] }
{ "m1.X": [1,1,1], "m1.Y": [1,0,2] }
{ "m1.X": [0,0,0], "m1.Y": [2,1,1] }
{ "m1.X": [1,0,0], "m1.Y": [2,1,1] }
{ "m1.X": [0,1,0], "m1.Y": [2,1,1] }
{ "m1.X": [0,0,1], "m1.Y": [2,1,1] }
{ "m1.X": [1,0,1], "m1.Y": [2,1,1] }
{ "m1.X": [0,1,1], "m1.Y": [2,1,1] }
{ "m1.X": [1,1,0], "m1.Y": [2,1,1] }
{ "m1.X": [1,1,1], "m1.Y": [2,1,1] }
{ "m1.X": [0,0,0], "m1.Y": [1,2,1] }
{ "m1.X": [1,0,0], "m1.Y": [1,2,1] }
{ "m1.X": [0,1,0], "m1.Y": [1,2,1] }
{ "m1.X": [0,0,1], "m1.Y": [1,2,1] }
{ "m1.X": [1,0,1], "m1.Y": [1,2,1] }
{ "m1.X": [0,1,1], "m1.Y": [1,2,1] }
{ "m1.X": [1,1,0], "m1.Y": [1,2,1] }
{ "m1.X": [1,1,1], "m1.Y": [1,2,1] }
{ "m1.X": [0,0,0], "m1.Y": [1,1,2] }
{ "m1.X": [1,0,0], "m1.Y": [1,1,2] }
{ "m1.X": [0,1,0], "m1.Y": [1,1,2] }
{ "m1.X": [0,0,1], "m1.Y": [1,1,2] }
{ "m1.X": [1,0,1], "m1.Y": [1,1,2] }
{ "m1.X": [0,1,1], "m1.Y": [1,1,2] }
{ "m1.X": [1,1,0], "m1.Y": [1,1,2] }
{ "m1.X": [1,1,1], "m1.Y": [1,1,2] }
;;
{ "m1.X": [3,3,3], "m1.Y": [2,3,1] }
{ "m1.X": [1,3,3], "m1.Y": [2,3,1] }
{ "m1.X": [3,1,3], "m1.Y": [2,3,1] }
{ "m1.X": [3,3,1], "m1.Y": [2,3,1] }
{ "m1.X": [1,3,1], "m1.Y": [2,3,1] }
{ "m1.X": [3,1,1], "m1.Y": [2,3,1] }
{ "m1.X": [1,1,3], "m1.Y": [2,3,1] }
{ "m1.X": [1,1,1], "m1.Y": [2,3,1] }
{ "m1.X": [3,3,3], "m1.Y": [3,2,1] }
{ "m1.X": [1,3,3], "m1.Y": [3,2,1] }
{ "m1.X": [3,1,3], "m1.Y": [3,2,1] }
{ "m1.X": [3,3,1], "m1.Y": [3,2,1] }
{ "m1.X": [1,3,1], "m1.Y": [3,2,1] }
{ "m1.X": [3,1,1], "m1.Y": [3,2,1] }
{ "m1.X": [1,1,3], "m1.Y": [3,2,1] }
{ "m1.X": [1,1,1], "m1.Y": [3,2,1] }
{ "m1.X": [3,3,3], "m1.Y": [3,1,2] }
{ "m1.X": [1,3,3], "m1.Y": [3,1,2] }
{ "m1.X": [3,1,3], "m1.Y": [3,1,2] }
{ "m1.X": [3,3,1], "m1.Y": [3,1,2] }
{ "m1.X": [1,3,1], "m1.Y": [3,1,2] }
{ "m1.X": [3,1,1], "m1.Y": [3,1,2] }
{ "m1.X": [1,1,3], "m1.Y": [3,1,2] }
{ "m1.X": [1,1,1], "m1.Y": [3,1,2] }
{ "m1.X": [3,3,3], "m1.Y": [2,1,3] }
{ "m1.X": [1,3,3], "m1.Y": [2,1,3] }
{ "m1.X": [3,1,3], "m1.Y": [2,1,3] }
{ "m1.X": [3,3,1], "m1.Y": [2,1,3] }
{ "m1.X": [1,3,1], "m1.Y": [2,1,3] }
{ "m1.X": [3,1,1], "m1.Y": [2,1,3] }
{ "m1.X": [1,1,3], "m1.Y": [2,1,3] }
{ "m1.X": [1,1,1], "m1.Y": [2,1,3] }
{ "m1.X": [3,3,3], "m1.Y": [1,2,3] }
{ "m1.X": [1,3,3], "m1.Y": [1,2,3] }
{ "m1.X": [3,1,3], "m1.Y": [1,2,3] }
{ "m1.X": [3,3,1], "m1.Y": [1,2,3] }
{ "m1.X": [1,3,1], "m1.Y": [1,2,3] }
{ "m1.X": [3,1,1], "m1.Y": [1,2,3] }
{ "m1.X": [1,1,3], "m1.Y": [1,2,3] }
{ "m1.X": [1,1,1], "m1.Y": [1,2,3] }
{ "m1.X": [3,3,3], "m1.Y": [1,3,2] }
{ "m1.X": [1,3,3], "m1.Y": [1,3,2] }
{ "m1.X": [3,1,3], "m1.Y": [1,3,2] }
{ "m1.X": [3,3,1], "m1.Y": [1,3,2] }
{ "m1.X": [1,3,1], "m1.Y": [1,3,2] }
{ "m1.X": [3,1,1], "m1.Y": [1,3,2] }
{ "m1.X": [1,1,3], "m1.Y": [1,3,2] }
{ "m1.X": [1,1,1], "m1.Y": [1,3,2] }
;;
{ "m1.X": [3,3,3], "m1.Y": [1,2,3] }
{ "m1.X": [1,3,3], "m1.Y": [1,2,3] }
{ "m1.X": [3,1,3], "m1.Y": [1,2,3] }
{ "m1.X": [3,3,1], "m1.Y": [1,2,3] }
{ "m1.X": [1,3,1], "m1.Y": [1,2,3] }
{ "m1.X": [3,1,1], "m1.Y": [1,2,3] }
{ "m1.X": [1,1,3], "m1.Y": [1,2,3] }
{ "m1.X": [1,1,1], "m1.Y": [1,2,3] }
{ "m1.X": [3,3,3], "m1.Y": [2,1,3] }
{ "m1.X": [1,3,3], "m1.Y": [2,1,3] }
{ "m1.X": [3,1,3], "m1.Y": [2,1,3] }
{ "m1.X": [3,3,1], "m1.Y": [2,1,3] }
{ "m1.X": [1,3,1], "m1.Y": [2,1,3] }
{ "m1.X": [3,1,1], "m1.Y": [2,1,3] }
{ "m1.X": [1,1,3], "m1.Y": [2,1,3] }
{ "m1.X": [1,1,1], "m1.Y": [2,1,3] }
{ "m1.X": [3,3,3], "m1.Y": [1,3,2] }
{ "m1.X": [1,3,3], "m1.Y": [1,3,2] }
{ "m1.X": [3,1,3], "m1.Y": [1,3,2] }
{ "m1.X": [3,3,1], "m1.Y": [1,3,2] }
{ "m1.X": [1,3,1], "m1.Y": [1,3,2] }
{ "m1.X": [3,1,1], "m1.Y": [1,3,2] }
{ "m1.X": [1,1,3], "m1.Y": [1,3,2] }
{ "m1.X": [1,1,1], "m1.Y": [1,3,2] }
4 changes: 4 additions & 0 deletions testdata/lookup_11.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(deflookup test (m1.Y) (m1.Z))
(module m1)
(defalias Z X)
(defcolumns X Y)
37 changes: 37 additions & 0 deletions testdata/lookup_11.rejects
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ "m1.X": [1], "m1.Y": [2] }
;;
{ "m1.X": [1,2], "m1.Y": [1,1] }
{ "m1.X": [2,1], "m1.Y": [1,1] }
{ "m1.X": [2,2], "m1.Y": [1,1] }
;;
{ "m1.X": [1,2], "m1.Y": [1,3] }
{ "m1.X": [1,2], "m1.Y": [3,1] }
{ "m1.X": [1,2], "m1.Y": [1,1] }
{ "m1.X": [2,1], "m1.Y": [1,1] }
{ "m1.X": [2,1], "m1.Y": [1,3] }
{ "m1.X": [2,1], "m1.Y": [3,1] }
{ "m1.X": [2,2], "m1.Y": [1,3] }
{ "m1.X": [2,2], "m1.Y": [3,1] }
;;
{ "m1.X": [3,3,3], "m1.Y": [1,2,1] }
{ "m1.X": [1,3,3], "m1.Y": [1,2,1] }
{ "m1.X": [3,1,3], "m1.Y": [1,2,1] }
{ "m1.X": [3,3,1], "m1.Y": [1,2,1] }
{ "m1.X": [1,3,1], "m1.Y": [1,2,1] }
{ "m1.X": [3,1,1], "m1.Y": [1,2,1] }
{ "m1.X": [1,1,3], "m1.Y": [1,2,1] }
{ "m1.X": [1,1,1], "m1.Y": [2,2,2] }
{ "m1.X": [1,1,1], "m1.Y": [2,2,3] }
{ "m1.X": [1,1,1], "m1.Y": [3,2,2] }
{ "m1.X": [1,1,1], "m1.Y": [2,3,2] }
{ "m1.X": [3,3,3], "m1.Y": [1,1,2] }
{ "m1.X": [1,3,3], "m1.Y": [1,1,2] }
{ "m1.X": [3,1,3], "m1.Y": [1,1,2] }
{ "m1.X": [3,3,1], "m1.Y": [1,1,2] }
{ "m1.X": [1,3,1], "m1.Y": [1,1,2] }
{ "m1.X": [3,1,1], "m1.Y": [1,1,2] }
{ "m1.X": [1,1,3], "m1.Y": [1,1,2] }
{ "m1.X": [1,1,1], "m1.Y": [2,2,2] }
{ "m1.X": [1,1,1], "m1.Y": [3,2,2] }
{ "m1.X": [1,1,1], "m1.Y": [2,3,2] }
{ "m1.X": [1,1,1], "m1.Y": [2,2,3] }

0 comments on commit 34403f6

Please sign in to comment.