From 34403f6f04467d7dc113e0f4d9c4cdf3a2a9f79c Mon Sep 17 00:00:00 2001 From: David Pearce Date: Fri, 10 Jan 2025 23:07:36 +1300 Subject: [PATCH] fix: access qualified aliases from lookup (#531) * 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. --- pkg/corset/resolver.go | 53 +++++----- pkg/test/valid_corset_test.go | 4 + testdata/lookup_11.accepts | 175 ++++++++++++++++++++++++++++++++++ testdata/lookup_11.lisp | 4 + testdata/lookup_11.rejects | 37 +++++++ 5 files changed, 242 insertions(+), 31 deletions(-) create mode 100644 testdata/lookup_11.accepts create mode 100644 testdata/lookup_11.lisp create mode 100644 testdata/lookup_11.rejects diff --git a/pkg/corset/resolver.go b/pkg/corset/resolver.go index 7d5dd4d..3b50043 100644 --- a/pkg/corset/resolver.go +++ b/pkg/corset/resolver.go @@ -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 @@ -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 } @@ -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 diff --git a/pkg/test/valid_corset_test.go b/pkg/test/valid_corset_test.go index 4c685bf..7ef76cc 100644 --- a/pkg/test/valid_corset_test.go +++ b/pkg/test/valid_corset_test.go @@ -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 // =================================================================== diff --git a/testdata/lookup_11.accepts b/testdata/lookup_11.accepts new file mode 100644 index 0000000..d73f1e8 --- /dev/null +++ b/testdata/lookup_11.accepts @@ -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] } diff --git a/testdata/lookup_11.lisp b/testdata/lookup_11.lisp new file mode 100644 index 0000000..4ab07c1 --- /dev/null +++ b/testdata/lookup_11.lisp @@ -0,0 +1,4 @@ +(deflookup test (m1.Y) (m1.Z)) +(module m1) +(defalias Z X) +(defcolumns X Y) diff --git a/testdata/lookup_11.rejects b/testdata/lookup_11.rejects new file mode 100644 index 0000000..95f7628 --- /dev/null +++ b/testdata/lookup_11.rejects @@ -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] }