Skip to content

Commit

Permalink
Принудительные обобщения в куче мест для борьбы с распуханием № 3 (#359)
Browse files Browse the repository at this point in the history
По-нормальному, нужно каждый случай обобщения описать, сделать выводы
и решить проблему в общем случае в рамках #332. А пока я анализировал
лог и подсекал наиболее явные точки распухания.
  • Loading branch information
Mazdaywik committed Jul 31, 2021
1 parent 13fc222 commit b1d5a2b
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 44 deletions.
8 changes: 4 additions & 4 deletions src/compiler/Checker-Screening.ref
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ MakePairs {
*/
CheckFunction {
((Function s.ScopeClass (e.Name) Sentences e.Sentences) t.SrcPos)
= <CheckSentences t.SrcPos (e.Name) () () (e.Sentences)>
= <CheckSentences t.SrcPos (e.Name) (<gen_e__>) (<gen_e__>) (e.Sentences)>
}

/*
Expand Down Expand Up @@ -114,7 +114,7 @@ CheckSentences {
<MapAccum
{
s.Num ((e.Pattern) e.AssignsOrConds (e.Result) (e.Blocks))
= e.Prefix '$' <Symb s.Num> : e.Prefix^
= <gen_e__ e.Prefix '$' <Symb s.Num>> : e.Prefix^
= <gen_e__ e.ContextVars e.Pattern> : e.ContextVars^
= <Map
{
Expand All @@ -136,14 +136,14 @@ CheckSentences {
t.SrcPos
(e.FuncName)
(e.Prefix)
(e.ContextVars e.ContextAllAssignsOrConds)
(<gen_e__ e.ContextVars e.ContextAllAssignsOrConds>)
((e.Pattern) e.AssignsOrConds (e.Result) (e.Blocks))
>
<CheckSentenceBlocks
t.SrcPos
(e.FuncName)
(e.Prefix)
(e.ContextVars e.ContextAllAssignsOrConds)
(<gen_e__ e.ContextVars e.ContextAllAssignsOrConds>)
((e.Pattern) e.AssignsOrConds (e.Result) (e.Blocks))
>
}
Expand Down
16 changes: 10 additions & 6 deletions src/compiler/Checker.ref
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ SeparateDefines {
(e.Declarations) (NativeBlock e.Block) =
(e.Declarations);
}
(/* объявления */)
(<gen_e__ /* объявления */>)
e.AST
>;
}
Expand Down Expand Up @@ -766,7 +766,7 @@ CheckRedefinitions {

CheckFunctionBody {
(e.Body) =
<CheckFunctionBodyRec (/* vars */) e.Body>;
<CheckFunctionBodyRec (<gen_e__ /* vars */>) e.Body>;
}

CheckFunctionBodyRec {
Expand Down Expand Up @@ -846,14 +846,18 @@ DoCheckAssignments {

= <DoCheckAssignments
(e.Assignments) (e.ScopeVars)
e.Errors
e.ResultFunctionsAndErrors
e.BlocksFunctionsAndErrors
e.PatternFunctionsAndErrors
<gen_e__
e.Errors
e.ResultFunctionsAndErrors
e.BlocksFunctionsAndErrors
e.PatternFunctionsAndErrors
>
s.Backtrack
>;
}

gen_e__ { e.arg = e.arg }

FixBacktrackForOpenEVars {
e.Pattern OneWay, <FindOpenEVars e.Pattern> : /* пусто */ = OneWay;

Expand Down
7 changes: 5 additions & 2 deletions src/compiler/Desugaring.ref
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ Pass-FlatNestedFuncs {
ExtractNested {
s.MarkupContext e.Sentences
= <ExtractNestedRec
s.MarkupContext (/* внешних переменных нет */) e.Sentences
s.MarkupContext (<gen_e__ /* внешних переменных нет */>) e.Sentences
>
: (/* заимстовованных переменных нет */) (e.NestedFuncs) e.Sentences^
= (e.NestedFuncs) e.Sentences;
Expand All @@ -656,7 +656,10 @@ ExtractNestedRec {
s.MarkupContext (e.ScopeVars) Sentences e.Sentences
= <MapAccum
(&ExtractNested-Sentence s.MarkupContext e.ScopeVars)
((/* вложенные функции */) (/* заимствованные переменные */))
(
(<gen_e__ /* вложенные функции */>)
(<gen_e__ /* заимствованные переменные */>)
)
e.Sentences
>
: ((e.NestedFuncs) (e.BorrowedVars)) e.Sentences^
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/GenericMatch.ref
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,7 @@ AddContraction-Spec {
t._ = s.OpenFlag;
}
: s.OpenFlag^
= <gen_t__ t.toAdd> : t.toAdd^
= <SimplifyCoordinates
(
s.OpenFlag
Expand All @@ -2215,6 +2216,8 @@ AddContraction-Spec {
>;
}

gen_t__ { e.arg = <gen_e__ e.arg> }

AddContraction-Spec-Symm {
t.toAdd (s.OpenFlag e.Contrs) e.SymmClashes (e.Assigns)
= t.toAdd
Expand Down
15 changes: 10 additions & 5 deletions src/compiler/Log-AST.ref
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,23 @@ Expression {
= <DoExpression FIRST (e.Indent) (e.Prefix) e.Expression (e.Suffix)>;
}

$SPEC DoExpression s.POS (e.indent) (e.out-line) e.expression;

DoExpression {
s.POS (e.indent) (e.out-line) e.expression
= <DoExpression-GEN
s.POS (<gen_e__ e.indent>) (<gen_e__ e.out-line>) <gen_e__ e.expression>
>;
}

DoExpression-GEN {
s.Pos (e.Indent) (e.OutLine) /* пусто */ (e.Suffix) = (e.OutLine e.Suffix);

s.Pos (e.Indent) (e.OutLine) t.NextTerm e.Expr (e.Suffix)
= <InlineTerm t.NextTerm> : e.TextualTerm
= <AppendTerm e.OutLine (e.TextualTerm)> : e.NewOutLine
= <InlineTerm <gen_e__ t.NextTerm>> : e.TextualTerm
= <AppendTerm <gen_e__ e.OutLine> (e.TextualTerm)> : e.NewOutLine
= <LongLine e.NewOutLine>
: {
True
= e.Indent e.TextualTerm : e.OutLineTerm
= <gen_e__ e.Indent e.TextualTerm> : e.OutLineTerm
= <LongLine e.OutLineTerm>
: {
True, e.Expr : /* пусто */
Expand Down
12 changes: 7 additions & 5 deletions src/compiler/ParseCmdLine.ref
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ $ENTRY ParseCommandLine {
t.Config (e.Errors)
&Config-SetCompilerFlags s.Num ' -I"' e.Path '"'
>
(SearchFolder s.Num e.Path);
<gen_e__ (SearchFolder s.Num e.Path)>;

(t.Config e.Errors) (TargetFileName s.Num e.FileName)
= <Update
Expand Down Expand Up @@ -221,7 +221,7 @@ $ENTRY ParseCommandLine {
= <Update t.Config (e.Errors) &Config-SetTempDir s.Num e.Name>;

(t.Config e.Errors) (REF5RSL-Env s.Num)
= (t.Config e.Errors) (REF5RSL-Env s.Num);
= (t.Config e.Errors) <gen_e__ (REF5RSL-Env s.Num)>;

(t.Config e.Errors) (OverwriteExistRasls s.Num)
= <Update
Expand Down Expand Up @@ -255,16 +255,16 @@ $ENTRY ParseCommandLine {
= <Update t.Config (e.Errors) &Config-SetVerbose s.Num e.Value>;

(t.Config e.Errors) t.Option
= (t.Config e.Errors) t.Option;
= (t.Config e.Errors) <gen_e__ t.Option>;
}
)
(&MapAccum
{
(t.Config e.Errors) (SearchFolder s.Num e.Folder)
= (<Config-SetSearchFolder t.Config e.Folder> e.Errors);
= (<gen_e__ <Config-SetSearchFolder t.Config e.Folder> e.Errors>);

(t.Config e.Errors) (REF5RSL-Env s.Num)
= (<Config-SetSearchFolder t.Config REF5RSL> e.Errors);
= (<gen_e__ <Config-SetSearchFolder t.Config REF5RSL> e.Errors>);

(t.Config e.Errors) (FILE s.Num e.FileName)
= (t.Config e.Errors) (s.Num e.FileName);
Expand Down Expand Up @@ -326,6 +326,8 @@ $ENTRY ParseCommandLine {
>;
}

gen_e__ { e.arg = e.arg }

Update {
t.Config (e.Errors) s.Updater s.LineNum e.Option
= <s.Updater t.Config e.Option>
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/R5-Lexer.ref
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ IncLine {
(RowCol s.Line s.Col) = (RowCol <Inc s.Line> 1);
}

$DRIVE IncCol;

IncCol {
(RowCol s.Line s.Col) = (RowCol s.Line <Inc s.Col>);

Expand Down
41 changes: 22 additions & 19 deletions src/compiler/R5-Parser.ref
Original file line number Diff line number Diff line change
Expand Up @@ -243,30 +243,30 @@ NameList-DoNames {
t.ErrorList (e.Units) e.Tokens;

t.ErrorList s.Tag (e.Units) (TkComma t.Pos) e.Tokens
= <NameList-DoNames
<EL-AddErrorAt t.ErrorList t.Pos 'expected name after comma'>
s.Tag (e.Units) e.Tokens
>;
= <EL-AddErrorAt t.ErrorList t.Pos 'expected name after comma'>
: t.ErrorList^
= <NameList-DoNames t.ErrorList s.Tag (e.Units) e.Tokens>;

t.ErrorList s.Tag (e.Units)
(TkName t.NamePos e.Name) (TkOpenBlock t.BracketPos) e.Tokens
= <EL-AddErrorAt
t.ErrorList t.NamePos
'missed semicolon after previous ' <TokName s.Tag> ' declaration'
>
: t.ErrorList^
= t.ErrorList
(e.Units) (TkName t.NamePos e.Name) (TkOpenBlock t.BracketPos) e.Tokens;

t.ErrorList s.Tag (e.Units) (TkName t.Pos e.Name) e.Tokens
= <NameList-DoNames
<EL-AddErrorAt t.ErrorList t.Pos 'missed comma after the external name'>
s.Tag (e.Units) e.Tokens
>;
= <EL-AddErrorAt t.ErrorList t.Pos 'missed comma after the external name'>
: t.ErrorList^
= <NameList-DoNames t.ErrorList s.Tag (e.Units) e.Tokens>;

t.ErrorList s.Tag (e.Units) t.NextToken e.Tokens
, t.NextToken : (s.Type t.Pos e.Value)
, <OneOf s.Type TkExtern TkEntry TkEOF> : True
= <EL-AddErrorAt t.ErrorList t.Pos 'semicolon'>
(e.Units) t.NextToken e.Tokens;
= <EL-AddErrorAt t.ErrorList t.Pos 'semicolon'> : t.ErrorList^
= t.ErrorList (e.Units) t.NextToken e.Tokens;

t.ErrorList s.Tag (e.Units) t.NextToken e.Tokens
= <NameList-DoNames
Expand Down Expand Up @@ -524,18 +524,15 @@ SentenceTail {

CheckExceedBlocks {
t.ErrorList s.Mode e.ExceedBlocks
= <DoCheckExceedBlocks s.Mode t.ErrorList () e.ExceedBlocks>;
= <DoCheckExceedBlocks s.Mode t.ErrorList (<gen_e__>) e.ExceedBlocks>;
}

DoCheckExceedBlocks {
s.Mode t.ErrorList (e.ScannedBlocks) (t.Pos e.Body) e.RestBlocks
= <ClassicError t.ErrorList s.Mode t.Pos 'Exceed block in this position'>
: t.ErrorList^
= <DoCheckExceedBlocks
s.Mode
<ClassicError
t.ErrorList s.Mode t.Pos 'Exceed block in this position'
>
(e.ScannedBlocks (e.Body))
e.RestBlocks
s.Mode t.ErrorList (e.ScannedBlocks (e.Body)) e.RestBlocks
>;

s.Mode t.ErrorList (e.ScannedBlocks) /* empty */
Expand Down Expand Up @@ -633,7 +630,8 @@ Pattern {
Result {
t.ErrorList s.Mode e.Tokens
= <Result-Blocks
s.Mode (/* blocks */) <Expression t.ErrorList s.Mode Result e.Tokens>
s.Mode (<gen_e__ /* blocks */>)
<Expression t.ErrorList s.Mode Result e.Tokens>
>;
}

Expand Down Expand Up @@ -694,10 +692,12 @@ Expression {
>;
}

$INLINE TokenChain, Expression;

TokenChain {
t.ErrorList s.Mode s.Kind e.Tokens
= <DoTokenChain
s.Mode s.Kind t.ErrorList (<gen_e__ /* collected */>) e.Tokens
s.Mode s.Kind t.ErrorList (<gen_e__ /* collected */>) <gen_e__ e.Tokens>
>
}

Expand Down Expand Up @@ -762,12 +762,14 @@ DoTokenChain {
t.ErrorList s.Mode t.Pos 'Identifier expected after \'<\''
>
: t.ErrorList^
= <gen_e__ e.Collected> : e.Collected^
= <DoTokenChain-AfterCall
s.Mode s.Kind (e.Collected) t.Pos (/* no func name */)
<TokenChain t.ErrorList s.Mode s.Kind e.Tokens>
>;

(TkOpenCall t.Pos e.FuncName)
= <gen_e__ e.Collected> : e.Collected^
= <DoTokenChain-AfterCall
s.Mode s.Kind (e.Collected) t.Pos ((Symbol Name t.Pos e.FuncName))
<TokenChain t.ErrorList s.Mode s.Kind e.Tokens>
Expand Down Expand Up @@ -956,6 +958,7 @@ Expression-CheckBrackets {
= t.ErrorList t.Expression e.Tokens;
}

$DRIVE ClassicError;

ClassicError {
t.ErrorList Classic t.Pos e.Message
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/SR-Lexer.sref
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ ValidDirective {
'ESWAP' = (#TkDirective #ESwap);
'LABEL' = (#TkDirective #Ident);
'INCLUDE' = (#TkDirective #Include);
'EASTEREGG' = <Map { s.Char = (#TkChar s.Char); } $EASTEREGG>;
'EASTEREGG' = <Map { s.Char = (#TkChar s.Char); } <gen_e__ $EASTEREGG>>;
'SCOPEID'
= (#TkNumber #Cookie1) (#TkNumber #Cookie2)
(#TkWarning #deprecated '$SCOPEID is deprecated');
Expand Down
10 changes: 8 additions & 2 deletions src/compiler/SR-Parser.sref
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,14 @@ ParseSentencePart {
ParsePattern {
t.ErrorList e.Tokens
= <DoParsePattern
t.ErrorList (/* мультискобки */) (/* просканировано */) e.Tokens
t.ErrorList
(<gen_e__ /* мультискобки */>) (<gen_e__ /* просканировано */>)
e.Tokens
>;
}

gen_e__ { e.arg = e.arg; }

DoParsePattern {
// Обработка литералов атомов

Expand Down Expand Up @@ -612,7 +616,9 @@ StrFromBracket {
ParseResult {
t.ErrorList e.Tokens
= <DoParseResult
t.ErrorList (/* мультискобки */) (/* просканировано */) e.Tokens
t.ErrorList
(<gen_e__ /* мультискобки */>) (<gen_e__ /* просканировано */>)
e.Tokens
>
: t.ErrorList^ (e.Result) e.Tail
= <ParseBlocks t.ErrorList e.Tail> : t.ErrorList^ (e.Blocks) e.Tail^
Expand Down

0 comments on commit b1d5a2b

Please sign in to comment.