melt-umn / silver

An attribute grammar-based programming language for composable language extensions
http://melt.cs.umn.edu/silver/
GNU Lesser General Public License v3.0
59 stars 7 forks source link

No Silver error message for using a nonterminal with no concrete productions in a concrete production #172

Open remexre opened 7 years ago

remexre commented 7 years ago

(Yeah, bad issue name)

grammar test_error;

nonterminal Foo;
nonterminal Bar;

concrete production foo_c
top::Foo ::= b::Bar
{}

parser parse::Foo
{
  test_error;
}

This fails in the Copper stage with Undefined reference to test_error_Bar -- we should maybe try to give a better error message from Silver, something like "There is no concrete production that results in test_error:Bar, but test_error:Bar is used in the concrete production test_error:foo_c"

tedinski commented 7 years ago

At first, I thought maybe this would have to be caught during spec generation time, but I think this is actually something we can catch during normal grammar compilation. i.e. raising normals errors in concrete productions. We'd need to add new information to the Silver environment, though. The normal environment doesn't really track concrete syntax info (with the unfortunate exception of a hack to make easy terminals work...)

So maybe for now this could be solved during the spec error checking stuff of issue #20. The error check we'd perform there would give an error like "Nonterminal 'Bar' is used by this parser, but it has no concrete productions."

200sc commented 7 years ago

Its possible to add this to concreteSyntaxTypeErrors on productionRHSElem, but it raises an issue of environment knowledge-- adding this error check here:

top.concreteSyntaxTypeErrors <-
    case t.typerep of 
    | nonterminalTypeExp(name, _) ->
      if length(getProdsForNt(name, t.env)) != 0 then [] --top.env has the same behavior
      else [err(t.location, "Nonterminal " ++ t.pp ++ " is used by this parser, but is has no concrete productions.")]
    | _ -> []
    end;

The result is that importing a nonterminal with only and not importing any of its concrete productions will also report this error, which is currently done by the silver/extension/templating extension at the least. Its also worth noting that getProdsForNt has a comment recommending it isn't relied on.

tedinski commented 7 years ago

In addition to that comment, and that problem, it looks up productions, not concrete productions specifically.

ericvanwyk commented 7 years ago

Does Copper detect this error?

On Mon, Jun 12, 2017 at 2:48 PM, Ted Kaminski notifications@github.com wrote:

In addition to that comment, and that problem, it looks up productions, not concrete productions specifically.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/melt-umn/silver/issues/172#issuecomment-307901297, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOhdzMpGeObROy08jom8NgyM4LpyxDTks5sDZYfgaJpZM4NldT7 .

krame505 commented 7 years ago

Currently Copper crashes, I think with a NullPointerException? I don't remember the error exactly, but it is not very descriptive.

Lucas Kramer

On Mon, Jun 12, 2017 at 8:58 PM, Eric Van Wyk notifications@github.com wrote:

Does Copper detect this error?

On Mon, Jun 12, 2017 at 2:48 PM, Ted Kaminski notifications@github.com wrote:

In addition to that comment, and that problem, it looks up productions, not concrete productions specifically.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/melt-umn/silver/issues/172#issuecomment-307901297, or mute the thread https://github.com/notifications/unsubscribe-auth/ ADOhdzMpGeObROy08jom8NgyM4LpyxDTks5sDZYfgaJpZM4NldT7 .

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/melt-umn/silver/issues/172#issuecomment-307984359, or mute the thread https://github.com/notifications/unsubscribe-auth/AIE1ij0NnDeUbG1fwYpHE8dwigVfCPnSks5sDezfgaJpZM4NldT7 .

ericvanwyk commented 7 years ago

If nothing else this should also/only be a Copper bug then.

Any errors that involve analysis of the grammar (like this) should be done by Copper. If some are easy to check in Silver we can do that too I suppose.

On Mon, Jun 12, 2017 at 9:02 PM, Lucas Kramer notifications@github.com wrote:

Currently Copper crashes, I think with a NullPointerException? I don't remember the error exactly, but it is not very descriptive.

Lucas Kramer

On Mon, Jun 12, 2017 at 8:58 PM, Eric Van Wyk notifications@github.com wrote:

Does Copper detect this error?

On Mon, Jun 12, 2017 at 2:48 PM, Ted Kaminski notifications@github.com wrote:

In addition to that comment, and that problem, it looks up productions, not concrete productions specifically.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <https://github.com/melt-umn/silver/issues/172#issuecomment-307901297 , or mute the thread https://github.com/notifications/unsubscribe-auth/ ADOhdzMpGeObROy08jom8NgyM4LpyxDTks5sDZYfgaJpZM4NldT7 .

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/melt-umn/silver/issues/172#issuecomment-307984359, or mute the thread https://github.com/notifications/unsubscribe-auth/ AIE1ij0NnDeUbG1fwYpHE8dwigVfCPnSks5sDezfgaJpZM4NldT7 .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/melt-umn/silver/issues/172#issuecomment-307984931, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOhd0gae52wyLlwQWtqQJ05cMrTzrnIks5sDe3CgaJpZM4NldT7 .

200sc commented 7 years ago

Copper does not crash from this error, the message is from copper itself from this function. The function in question is very general and used in a good number of places, so it wouldn't be trivial to change the message in Copper.

I spent some time trying to put this into Silver when building a Parser Spec but it would be duplicating a lot of work that is already done in the concrete productions for Productions, and I agree it would make more sense to take place in Copper.

krame505 commented 2 years ago

I just tried this again since the Copper API change was finished, the error message given before the crash now points to the location of the nonterminal, but is otherwise still has the same unhelpful message:

Compiling test_error
    [./test_error/]
    [Test.ag]
Found silver:core
    [/usr/local/google/home/lkramer/melt/silver/generated/src/silver/core/Silver.svi]
Checking For Errors.
Generating Translation.
    [test_error]
Generating parser test_error:parse.
test_error/Test.ag:3.16 [parser test_error_parse]: Undefined reference to test_error_Bar
test_error/Test.ag:3.16 [parser test_error_parse]: Undefined reference to test_error_Bar

An error occured.  Silver stack trace follows. (To see full traces including java elements, SILVERTRACE=1)

(silver.compiler.composed.Default.Pmain in Pmain.java:116): Error while evaluating function silver:compiler:composed:Default:main
(silver.compiler.driver.PcmdLineRun in PcmdLineRun.java:126): Error while evaluating function silver:compiler:driver:cmdLineRun
(silver.compiler.driver.PperformActions in PperformActions.java:116): Error while evaluating function silver:compiler:driver:performActions
(silver.compiler.driver.util.PrunAll in PrunAll.java:116): Error while evaluating function silver:compiler:driver:util:runAll
    (last line repeats 5 more times)
(silver.core.PneqInteger in PneqInteger.java:114): Error while evaluating function silver:core:neqInteger
(DN.364): While evaling syn 'silver:compiler:driver:util:code' in 'silver:compiler:modification:copper:buildParserAction' (60b84649)
(DN.364): While evaling syn 'silver:core:iovalue' in 'silver:core:ioval' (76cb6b26)
(DN.364): While evaling syn 'silver:core:stateVal' in 'silver:core:bindIO' (7b0ad09a)
(silver.core.PunsafeTrace in PunsafeTrace.java:114): Error while evaluating function silver:core:unsafeTrace
(DN.288): While evaling local 'silver:core:bindIO:local:silver:core:IO_sv:12:2:stateVal' in 'silver:core:bindIO' (7b0ad09a)
(DN.364): While evaling syn 'silver:core:stateVal' in 'silver:core:bindIO' (421581cd)
(silver.core.PunsafeTrace in PunsafeTrace.java:114): Error while evaluating function silver:core:unsafeTrace
(DN.288): While evaling local 'silver:core:bindIO:local:silver:core:IO_sv:12:2:stateVal' in 'silver:core:bindIO' (421581cd)
(DN.364): While evaling syn 'silver:core:stateVal' in 'silver:core:bindIO' (4d256e0)
(silver.core.PunsafeTrace in PunsafeTrace.java:114): Error while evaluating function silver:core:unsafeTrace
(DN.364): While evaling syn 'silver:core:stateOut' in 'silver:core:bindIO' (43c9c0b5)
(silver.core.PunsafeTrace in PunsafeTrace.java:114): Error while evaluating function silver:core:unsafeTrace
(DN.288): While evaling local 'silver:core:bindIO:local:silver:core:IO_sv:11:2:stateOut' in 'silver:core:bindIO' (43c9c0b5)
(DN.364): While evaling syn 'silver:core:stateOut' in 'silver:core:bindIO' (74d9afea)
(silver.core.PunsafeTrace in PunsafeTrace.java:114): Error while evaluating function silver:core:unsafeTrace
(DN.364): While evaling syn 'silver:core:stateOut' in 'silver:core:bindIO' (54724e71)
(silver.core.PunsafeTrace in PunsafeTrace.java:114): Error while evaluating function silver:core:unsafeTrace
(DN.364): While evaling syn 'silver:core:stateOut' in 'silver:compiler:definition:concrete_syntax:copper:compileParserBean' (3e4f326e)
(DN.288): While evaling local 'silver:compiler:definition:concrete_syntax:copper:compileParserBean:local:silver:compiler:definition:concrete_syntax:copper:Misc_sv:44:2:val' in 'silver:compiler:definition:concrete_syntax:copper:compileParserBean' (3e4f326e)
(silver.compiler.definition.concrete_syntax.copper.PcompileParserBeanT in PcompileParserBeanT.java:184): Error while evaluating function silver:compiler:definition:concrete_syntax:copper:compileParserBeanT
(java.util.Hashtable in Hashtable.java:353): java.lang.NullPointerException
    1 up: edu.umn.cs.melt.copper.compiletime.auxiliary.SymbolTable in SymbolTable.java:45
    2 up: edu.umn.cs.melt.copper.compiletime.spec.grammarbeans.visitors.NumericParserSpecBuilder in NumericParserSpecBuilder.java:400