Bug 359864 - Xtext hangs on multiple parentheses styles
Summary: Xtext hangs on multiple parentheses styles
Status: REOPENED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.12.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: SR2   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-04 12:05 EDT by Andrew Gacek CLA
Modified: 2018-12-05 09:48 EST (History)
5 users (show)

See Also:
sebastian.zarnekow: indigo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Gacek CLA 2011-10-04 12:05:50 EDT
The following grammar causes xtext to hang while generating artifacts:


grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "mydsl"

Model:
	greetings+=Expr*;
	
Expr returns Expr:
	i=INT
|	'(' Expr ')'
|	'[' Expr ']'
|	'{' Expr '}'
;


This hangs with the following output:


0    [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering platform uri 'C:\eclipse-xtext\workspace'
606  [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\eclipse-xtext\workspace\org.xtext.example.mydsl\..\org.xtext.example.mydsl\src-gen
637  [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\eclipse-xtext\workspace\org.xtext.example.mydsl\..\org.xtext.example.mydsl.ui\src-gen
776  [main] INFO  ipse.xtext.generator.LanguageConfig  - generating infrastructure for org.xtext.example.mydsl.MyDsl with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, SerializerFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, GeneratorFragment, FormatterFragment, LabelProviderFragment, OutlineTreeProviderFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment, Junit4Fragment, TypesGeneratorFragment, XbaseGeneratorFragment, CodetemplatesGeneratorFragment, RefactorElementNameFragment, CompareFragment
2034 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'mydsl' from 'file:/C:/eclipse-xtext/workspace/org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/MyDsl.genmodel'
Comment 1 Sebastian Zarnekow CLA 2011-10-05 03:21:52 EDT
Quoting the newsgroup:

it works if you dont choose the experimental features in the xtext project wizard.
it works with the 2.1.0 nightlys with the experimental features neither. 

Seems to be related to one of the new fragments.
Comment 2 Marcin Lewandowski CLA 2011-10-12 08:13:21 EDT
Seems like I got similar problem with my grammar. The MWE workflow hangs on the new experimental Serializer fragment, but works on the old one. During debug mode it appears to loop on finding alternatives. I can provide more details if required.
Comment 3 Sebastian Zarnekow CLA 2011-10-12 08:18:37 EDT
(In reply to comment #2)
> I can provide more details if required.

A grammar snippet would help if it looks different from the case in comment #0
Comment 4 Sebastian Zarnekow CLA 2011-10-13 10:10:39 EDT
Reproducable with this even simpler example:

Expr :
          i=INT
	| '(' Expr ')'
	| '[' Expr ']'
	| '{' Expr '}'
;
Comment 5 Moritz Eysholdt CLA 2011-10-17 10:16:23 EDT
fixed & pushed to master: 
http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/commit/?id=505f6a2976400fc96352e57aa1e3b02bb66bada2

Thanks for the minimal example. It made it much easier to track down the problem.

The problem was that syntactically, INT can be prefixed with any amount of "(", "[", or "{". In the code that is generated by the SerializerFragment, this is visualized using grammar notation: ("(" | "[" | "{")*. The internal algorithm which converts state machines to grammar snippets didn't detect alternatives with cardinality * correctly.
Comment 6 Andrew Gacek CLA 2017-09-13 12:43:44 EDT
This bug seems to have re-appeared. The example hangs in Xtext 2.12.0.
Comment 7 Sebastian Zarnekow CLA 2017-09-13 12:57:16 EDT
This is the stack when the generator hangs:

GenerateMyDsl.mwe2 [Mwe2 Launch]	
	org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher at localhost:54878	
		Thread [main] (Suspended)	
			System.identityHashCode(Object) line: not available [native method]	
			HashMap$TreeNode<K,V>.tieBreakOrder(Object, Object) line: 1896	
			HashMap$TreeNode<K,V>.putTreeVal(HashMap<K,V>, Node<K,V>[], int, K, V) line: 1992	
			LinkedHashMap<K,V>(HashMap<K,V>).putVal(int, K, V, boolean, boolean) line: 637	
			LinkedHashMap<K,V>(HashMap<K,V>).put(K, V) line: 611	
			LinkedHashSet<E>(HashSet<E>).add(E) line: 219	
			PdaUtil$HashStack<T>.push(T) line: 71	
			PdaUtil.filterEdges(Pda<S,P>, Traverser<Pda<S,P>,S,R>, Map<S,Integer>, PdaFactory<D,S,P,S>) line: 454	
			ContextTypePDAProvider.collectTypes(Pda<ISerState,RuleCall>, Map<ISerState,Integer>) line: 241	
			ContextTypePDAProvider.getContextTypePDAs(Grammar) line: 264	
			SyntacticSequencerPDAProvider.getSyntacticSequencerPDAs(Grammar) line: 596	
			SemanticSequencerNfaProvider.getSemanticSequencerNFAs(Grammar) line: 239	
			GrammarConstraintProvider.getConstraints(Grammar) line: 621	
			SemanticSequencerExtensions.xtend line: 97	
			SerializerFragment2.xtend line: 212	
			SerializerFragment2.xtend line: 141	
			CompositeGeneratorFragment2.xtend line: 40	
			XtextGenerator.xtend line: 168	
			XtextGenerator(AbstractWorkflowComponent).invoke(WorkflowContext, ProgressMonitor, Issues) line: 126	
			Mwe2Bridge.invoke(IWorkflowContext) line: 34	
			XtextGenerator(AbstractWorkflowComponent).invoke(IWorkflowContext) line: 201	
			Workflow(AbstractCompositeWorkflowComponent).invoke(IWorkflowContext) line: 35	
			Workflow.run(IWorkflowContext) line: 19	
			Mwe2Runner.run(Module, Map<String,String>, IWorkflowContext) line: 102	
			Mwe2Runner.run(URI, Map<String,String>, IWorkflowContext) line: 62	
			Mwe2Runner.run(URI, Map<String,String>) line: 52	
			Mwe2Launcher.run(String[]) line: 78	
			Mwe2Launcher.main(String[]) line: 36
Comment 8 Lucas Wagner CLA 2018-11-01 10:18:06 EDT
Hi,

I am curious when this bug might be resolved, and if not resolved, are there any workarounds?

Currently we are exercising this bug on a language we're using for a production tool. The good news is the language generates after a lengthy period of time, about half an hour. I've observed that it takes roughly half an hour no matter what machine I'm running it on. Is it possible that after some timeout that the tool uses a different language generator? If so, is that timeout configurable? The half hour wait period is not intolerable, but is a bit of an obstacle when trying to train others in the tool's development.

I'm running Photon with Xtext 2.14 and still seeing this issue.

Thanks!
Comment 9 Christian Dietrich CLA 2018-12-05 02:36:32 EST
@Lucas. could you please provide a minimal reproducing grammar?
Comment 10 Lucas Wagner CLA 2018-12-05 09:47:39 EST
The following grammar takes roughly 3 minutes to generate. So it does not hang any longer, but does seem rather inefficient.

Expr :
          i=INT
	| '(' Expr ')'
	| '[' Expr ']'
	| '{' Expr '}'
;

This was tested just now on Photon 4.8.0 and Xtext 2.16.
Comment 11 Lucas Wagner CLA 2018-12-05 09:48:39 EST
The following grammar takes roughly 3 minutes to generate. So it does not hang any longer, but does seem rather inefficient.

Expr :
          i=INT
	| '(' Expr ')'
	| '[' Expr ']'
	| '{' Expr '}'
;

This was tested just now on Photon 4.8.0 and Xtext 2.16.