Skip to content
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

Fix duplicate procedure name issue. #1256

Closed
wants to merge 142 commits into from
Closed

Conversation

Fumuran
Copy link
Contributor

@Fumuran Fumuran commented Feb 21, 2024

Currently if we try to compile two programs in one context, which contain procedures with the same names, this will lead to a DuplicateProcName error. However we need to be able to do so while compiling transaction with multiple notes.
To achieve this, error was replaced with a warning log message.
This change should not lead to any issues with procedures parsing, compilation and execution.

Related issue: 0xPolygonMiden/miden-base#443

bobbinth and others added 30 commits October 11, 2023 21:06
The sentence describing the column $k_0$ had its order reversed, and the
table headers were incorrectly named as $x_i$ and $y_i$ instead of $a_i$
and $b_i$ as described in the introduction.
… info

This commit changes the `import_info` fields of ProgramAst and ModuleAst
to remove the `Option` wrapper, since it does not appear to serve a
specific purpose, and both complicates access to the imports, and
requires redundant code in a few places to access common information
from the imports. It also required fallible checks in a few places where
empty module import info would be suitable as a fallback.

After this change, one can access the ModuleImports struct directly on
both ProgramAst and ModuleAst via the `import_info` function, which
returns a reference to the field. Redundant functions in both structs
were removed if they are already provided by ModuleImports.
docs(mdbook): minor change in the bitwise chiplet
Expand capabilities of the `debug` instruction
…dler

Add `emit` instruction and host event handler
* ContextId type

* propagate MemoryContextId

* fix tests

* MemoryContextId -> ContextId

* move definition

* Remove derive-more dependency

* fix repl

* fmt

* docstring

* import newline

* Remove `Sub` from `ContextId`

* blank line

* section name change

* blank line

* use `ContextId::root()`

* fmt

* memory context -> execution context
@@ -3,7 +3,7 @@ use super::{
NamedProcedure, Procedure, ProcedureCache, ProcedureId, ProcedureName, RpoDigest, ToString,
Vec,
};
use crate::ast::{ModuleAst, ProgramAst};
use crate::ast::{event, Level, ModuleAst, ProgramAst};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it is odd to import the tracing::event macro from the ast module. Maybe import it directly?

@@ -428,7 +428,7 @@ impl ModuleContext {
if self.compiled_procs.iter().any(|p| p.name() == name)
|| self.proc_stack.iter().any(|p| &p.name == name)
{
return Err(AssemblyError::duplicate_proc_name(name, &self.path));
event!(Level::WARN, "duplicate proc name '{}' in module {}", name, &self.path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if we have two notes with the same procedure name, but different implementations? If I understood correctly, this would favor the first implementation, and use the same code for both notes. If that is the case, I think we need some different approach, perhaps compile both, and check that the MASTs are the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I thought that compilation of the notes will be performed in different ModuleContexts, but it's not, and that's the core issue. I dived into implementation of the compilation in the VM, but forgot to check how actually notes are compiled.

I think we will need to make some changes in both miden-base and miden-vm. Currently we are compiling each note (which contains ProgramAst and not ModuleAst, which is important) not only in one AssemblyContext, but also in one ModuleContext which is being created within the AssemblyContext creation. So, IMHO, to make it work we need to create a new ModuleContext for each note, which is currently impossible: we create a new ModuleContext of we create an AssemblyContext for program or if we start to compile a new module.
So in other words we need a new function in the Assembler, which will work similar to the compile_in_context(), but will create a new ModuleContext inside the AssemblyContext and compile the provided program using it.
After that in the miden-base inside the compile_notes function we will need to change the compile_in_context function to the newly created one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this become a non-issue when we switch to using MAST as the compilation artifact? In other words, notes will be compiled separately to MAST ahead-of-time, rather than from MASM on-demand. Then a transaction script program (also in MAST form), would either reference the notes by MAST root, or would inline the MAST for the note into itself. To be clear, I know that isn't the case right now, but I'm referring to once we make the changes described in #1226 and #1217 and switch away from using MASM as the artifact.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also 0xPolygonMiden/compiler#132, which is a draft spec for those changes as well as the binary format for the MAST. The draft is being worked on there temporarily, it will be moved to this repo once I've worked through the first iteration of feedback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should solve this issue indeed!

Copy link
Contributor

@bitwalker bitwalker Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we punt on solving this problem temporarily until that's done then? I think we're basically at the point where we can start doing the work to make that happen, we've just been taking our time with working through some of the details - but the PR I linked is basically the result of gathering the pieces of all those discussions together into a draft spec, and once we're happy with it, we can start implementing basically right away.

Bobbin recently mentioned in one of our conversations that you would probably be doing the implementation @Overcastan (if not both of us), though that's obviously not set in stone, but if you have any thoughts on the draft spec before I open it as a proper proposal here in the miden-vm repo, feel free to jump in as a reviewer.

In the meantime, it seems like it might be best to make the case of duplicate procedure names with differing MAST roots an error, to avoid accidentally treating them as equivalent. Then, once we implement the MAST changes, the practical issue with note scripts goes away.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - I think it makes sense to hold off on solving this as it will become a non-issue once we use MAST-based format to represent note scripts and account code. We should start working more actively on this starting next week, and hopefully, within 2 - 3 weeks we can be in a place where is issue becomes irrelevant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this issue is basically in the same boat as #1211.

@plafer
Copy link
Contributor

plafer commented Apr 29, 2024

@Overcastan are you still working on this?

@bobbinth
Copy link
Contributor

This may have been fixed by #1277. cc @bitwalker.

@bitwalker
Copy link
Contributor

I know that #1277 will raise an error if you try to define duplicate procedures in the same module, or try to compile a module graph with duplicate modules, so I believe this is solved as of the merge of #1277.

@bobbinth
Copy link
Contributor

bobbinth commented May 2, 2024

Closing as superseded by #1277.

@bobbinth bobbinth closed this May 2, 2024
@hackaugusto hackaugusto deleted the andrew-duplicate-proc-fix branch May 2, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.