Skip to content

Solution to conditionally dump overrides#127

Open
amir734jj wants to merge 11 commits intoboyland:masterfrom
amir734jj:user/amir734jj/codegen-override
Open

Solution to conditionally dump overrides#127
amir734jj wants to merge 11 commits intoboyland:masterfrom
amir734jj:user/amir734jj/codegen-override

Conversation

@amir734jj
Copy link
Copy Markdown
Contributor

@amir734jj amir734jj commented Jul 23, 2024

This PR generates working scala code for both flat.aps and over.aps

@amir734jj amir734jj changed the title working solution to conditionally dump overrides Solution to conditionally dump overrides Jul 23, 2024
@amir734jj amir734jj changed the title Solution to conditionally dump overrides (WIP) Solution to conditionally dump overrides Jul 23, 2024
Copy link
Copy Markdown
Owner

@boyland boyland left a comment

Choose a reason for hiding this comment

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

But see if we can find counter-examples before changing things in this PR


extern Declaration module_TYPE;
extern Declaration module_PHYLUM;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Interesting!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These two global static variables were originally defined for canonical stuff. So I thought let's reuse them.

switch (Declaration_KEY(item)) {
case KEYsome_function_decl:
if (!strcmp(
symbol_name(def_name(some_function_decl_def(item))),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can't you compare symbols here? That's teh point of symbols: faster than comparing strings. symbols are "eq" is equal (or there's a bug).

dump_function_prototype(name,fty,oss);
Declaration mdecl = get_enclosing_some_class_decl(decl);
std::set<Declaration> visisted;
dump_function_prototype(name,fty, check_override_decl(some_class_decl_result_type(mdecl), decl, visisted), oss);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

To me this looks like you might be adding overrides to functions in class declarations. That seems fishy to me. But it should cause many problem if it's a problem. Does basic.sala get created correctly?
Also: what if the function is at the top-level? I'd expect this code to crash. It doesn't crash?

}

return check_override_decl(result, fdecl, visited);
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not quite. This should check the rtype, or you might miss something. Let me see if I can create a counter-example, before you change anything. If my guess is right (and it might not be), then the example will miss an override.

@amir734jj amir734jj changed the title (WIP) Solution to conditionally dump overrides Solution to conditionally dump overrides Jul 23, 2024
Copy link
Copy Markdown
Owner

@boyland boyland left a comment

Choose a reason for hiding this comment

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

Looks pretty good, but:

  • What if the same decl name is used with a different return type? If that's a Scala error, then is the APS bad too? I would think so? Or does APS allow overriding? I think not.
  • check_override_decl seems better named something like: "type_has_service_function" or something that says it is checking whether this type exports a service function (not a value?) with the given name (and maybe with the given return type).
  • The name should reflect that it is asking a question about the APS, not about Scala per se and how APOS is implemented. (overriding)

}
}

bool check_override_decl(Declaration decl, Declaration fdecl) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you give a quick synopsis of what this function does?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Perhaps refactor to just take a Symbol for the second parameter, and rename the function as "hasExport" or something, and then the synopsis is that the type provides a function service with the given name.

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.

2 participants