Skip to content

fix: Tests.Action.Prog: defaultPrimsProg clobbers 'main'#292

Merged
mergify[bot] merged 1 commit intomainfrom
brprice/fix-defaultPrimsProg
Mar 13, 2022
Merged

fix: Tests.Action.Prog: defaultPrimsProg clobbers 'main'#292
mergify[bot] merged 1 commit intomainfrom
brprice/fix-defaultPrimsProg

Conversation

@brprice
Copy link
Copy Markdown
Contributor

@brprice brprice commented Mar 7, 2022

The definition of defaultEmptyProg is a hack, hardcoding an ID of 0 for
'main' and 2 for 'other', regardless of whether they are fresh or not.
This leads to two different defs having ID 0 in defaultPrimsProg as
normally used in progActionTest, and it turns out that 'main' is
overwritten with a primitive definition. Thus one cannot do any edits to
ID 0 in tests.

Note that whilst we have worked around this symptom, the implementation
of defaultEmptyProg is still wrong: these IDs will clash with some node
IDs in the current usage.

@brprice brprice requested a review from georgefst March 7, 2022 14:57
@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Mar 7, 2022

Reviewer note: this targets brprice/rename-prim-clash, but doesn't really depend on it, I just am submitting the PR as it appears in my history. I am happy to rebase onto main if wanted.

@dhess
Copy link
Copy Markdown
Member

dhess commented Mar 7, 2022

I'd prefer to fix the core issue. It shouldn't be difficult, right?

(In one of my recent testing commits, I needed to construct some a non-trivial test program for use in an App and ended up copying some code into the test harness from an unexported bit of code in Primer.App. Point is — we should probably make it easier to construct valid programs programatically.)

@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Mar 7, 2022

I'd prefer to fix the core issue. It shouldn't be difficult, right?

I don't think it will be too difficult, but is a pain. The way I can see to do it is to return the ID of main and other alongside the Prog, or to just look them up by name. In either case, this requires making a bunch of tests less readable. Perhaps you have a better idea in mind?

I agree in principle, and am happy to circle back to this after I have my imports PR up. (I needed to make this change to make an import test work properly, and this was the expedient change.) I could either modify this PR, or open a new PR. In either case basing the import PR off this hopefully keeps it easier to review.

@dhess
Copy link
Copy Markdown
Member

dhess commented Mar 7, 2022

Here's what I did in the primer-rel8 test harness. (As noted in the comment, I argue that this should be moved into Primer.App, as there is a hardcoded implementation of it there already that could be subsumed by this one.)

mkTestDefs :: [ASTDef] -> Map Name PrimFun -> (Map ID Def, ID)

You give it a list of user-defined definitions, and a map of primitive functions, and it gives back a properly-constructed progDefs, plus the next valid ID.

@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Mar 8, 2022

One thing to bear in mind here is that we plan to add namespacing to modules: we should scope IDs/names to a module, and then this clobbering will not be a problem any more. See https://github.com/hackworthltd/primer/pull/293/files#r821588210. Thus it may be more efficient to address this issue properly at that time.

Copy link
Copy Markdown
Contributor

@georgefst georgefst left a 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 mind whether we merge this now or wait for a proper fix via the module system.

@dhess
Copy link
Copy Markdown
Member

dhess commented Mar 8, 2022

I'm OK either way, as well.

@brprice brprice force-pushed the brprice/rename-prim-clash branch from 83ce3e9 to 2e40822 Compare March 10, 2022 10:38
The definition of defaultEmptyProg is a hack, hardcoding an ID of 0 for
'main' and 2 for 'other', regardless of whether they are fresh or not.
This leads to two different defs having ID 0 in defaultPrimsProg as
normally used in progActionTest, and it turns out that 'main' is
overwritten with a primitive definition. Thus one cannot do any edits to
ID 0 in tests.

Note that whilst we have worked around this symptom, the implementation
of defaultEmptyProg is still wrong: these IDs will clash with some node
IDs in the current usage.
@brprice brprice force-pushed the brprice/fix-defaultPrimsProg branch from 59d07e6 to 32e1cae Compare March 10, 2022 10:40
@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Mar 10, 2022

I'll open an issue to circle back after finishing modules
EDIT: see #296

@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Mar 10, 2022

I rebased onto brprice/rename-prim-clash, which itself has been rebased onto main. @dhess: once CI passes, could you merge? Thanks

Base automatically changed from brprice/rename-prim-clash to main March 13, 2022 13:02
@dhess dhess added the Ready to merge Ready to merge label Mar 13, 2022
mergify Bot added a commit that referenced this pull request Mar 13, 2022
@mergify mergify Bot merged commit 791db90 into main Mar 13, 2022
@mergify mergify Bot deleted the brprice/fix-defaultPrimsProg branch March 13, 2022 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge Ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants