-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update compiler to consume local imports #2116
Conversation
ae9d114
to
8946248
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of thoughts
existingNames []string | ||
// In an import context, this is the folder containing | ||
// the importing schema (as opposed to imported schemas) | ||
sourceFolder string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like how I need to plumb this through three levels in order to get it to the next compilation context. I'd welcome recommendations on a different way to structure this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't you put it on the translationContext?
@@ -22,6 +23,8 @@ type translationContext struct { | |||
mapper input.PositionMapper | |||
schemaString string | |||
skipValidate bool | |||
existingNames []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a *mapz.Set
up and down the stack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely
0653113
to
775de22
Compare
existingNames []string | ||
// In an import context, this is the folder containing | ||
// the importing schema (as opposed to imported schemas) | ||
sourceFolder string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't you put it on the translationContext?
// TODO: do we want this sort of logging here? | ||
log.Trace().Str("schema", string(schemaBytes)).Str("file", filepath).Msg("read schema from file") | ||
|
||
compiled, err := Compile(InputSchema{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you call an internal compile, then this could be passed the translationContext directly and then you wouldn't need a different context here or the need to pass it into Compile
35995e0
to
ccf4d79
Compare
|
||
func ImportFile(importContext *ImportContext) (*CompiledSchema, error) { | ||
relativeFilepath := constructFilePath(importContext.pathSegments) | ||
filePath := path.Join(importContext.sourceFolder, relativeFilepath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the imports are outside of the root context folder? is that supported, and if not, what kind of opinions/guidelines does it impose on the structure of a composable schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No; the eventual goal will be to support this using git-based imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The biggest effect that I see is that you won't be able to do a relative import within the package that walks up a directory. this means that you couldn't have:
app1/app1.zed
app2/app2.zed
util.zed
and have both app files reference the util file. I have a feeling this will be a tripping point; it'll either have to be well-documented or something we change.
@@ -1,6 +1,6 @@ | |||
--- | |||
name: "Lint" | |||
on: # yamllint disable-line rule:truthy | |||
on: # yamllint disable-line rule:truthy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change and below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yamllint
wants two spaces before an inline comment and appeared to be failing the lint check as a result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blech
|
||
const SchemaFileSuffix = ".zed" | ||
|
||
func ImportFile(importContext *ImportContext) (*CompiledSchema, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you see a need to export this, should we just keep this internal (i.e. lowercase)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works for me
85172fc
to
66f9d26
Compare
@@ -68,12 +72,21 @@ func AllowUnprefixedObjectType() ObjectPrefixOption { | |||
return func(cfg *config) { cfg.objectTypePrefix = new(string) } | |||
} | |||
|
|||
func SourceFolder(sourceFolder string) Option { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a doc comment explaining what this does. Probably good to add doc comments to the other exported functions too
"github.com/authzed/spicedb/pkg/genutil/mapz" | ||
) | ||
|
||
type ImportContext struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this context unexported as well
|
||
const SchemaFileSuffix = ".zed" | ||
|
||
func importFile(importContext *ImportContext) (*CompiledSchema, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this take in a *
vs just the importContext struct itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly me not having built an intuition yet for when you would use one vs the other.
return nil, fmt.Errorf("failed to read schema file: %w", err) | ||
} | ||
// TODO: do we want this sort of logging here? | ||
log.Trace().Str("schema", string(schemaBytes)).Str("file", filePath).Msg("read schema from file") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes; trace is good
log.Trace().Str("schema", string(schemaBytes)).Str("file", filePath).Msg("read schema from file") | ||
|
||
compiled, err := compileImpl(InputSchema{ | ||
// TODO: should this point to the schema file? What is this for? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes; it gives the file path for error messaging
80aa245
to
6cba14f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
6cba14f
to
f8ceb8e
Compare
Description
Part of getting composable schemas implemented. This actually implements the traversal.
Notes
This is intentionally incremental, and is not intended to be the release candidate. Future work includes:
Changes
existingNames
value through the compiler so that it can track the definitions it's already seenTesting
Review. See that tests go green.