Skip to content

Commit 55a0fe7

Browse files
KJ-14 Investigated the ability to use generalized context rules for default elab heating. So far not usable. K issue opened.
1 parent 338ca44 commit 55a0fe7

1 file changed

Lines changed: 60 additions & 42 deletions

File tree

semantics/elaborate-blocks.k

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ syntax K ::= "elabInstanceInit"
5656
syntax K ::= "elab" "(" K ")"
5757

5858
//@ Wraps the elaboration result. Since elaboration may happen at both ElaborationPhase and ExecutionPhase, it cannot be KResult. Actually it is not KResult for HOLE, but is for CHOLE.
59-
syntax K ::= "elabRes" "(" K ")"
59+
syntax ElabRes ::= "elabRes" "(" K ")"
6060

6161
//@Sets the enclosing object for a given object.
6262
//@Invoked by invokeConstr and QSuperConstrInv.
@@ -274,20 +274,40 @@ rule [elabParamsEnd]:
274274

275275
/*@ \subsection{Elaboration of code blocks} */
276276

277-
//@ Heating arguments for both expression and statement terms.
278-
//@ The attribute [transition-strictness] is used as transition attribute for testing strictness.
279-
//@ This is a rule that may lead to unexpected nondeterminism if it is wrongly implemented.
280-
//@ In order to expose incorrect nondeterminism we need to model-check a program that exposes the nondeterminism.
277+
//todo custom elab heating rule
278+
/*@ Heating arguments for both expression and statement terms.
279+
The attribute [transition-strictness] is used as transition attribute for testing strictness.
280+
This is a rule that may lead to unexpected nondeterminism if it is wrongly implemented.
281+
In order to expose incorrect nondeterminism we need to model-check a program that exposes the nondeterminism.
282+
*/
281283
rule [elabHeatDefault]:
282284
(. => elab(K)) ~> elab(KL:KLabel(HeadKs:KList,, (K:K => CHOLE),, TailKs:KList))
283285
when
284286
defaultElabChildren(KL)
285287
//notBool customElabChildren(KL)
286288
andBool notBool isElab(K)
287-
//andBool notBool isElabNaked(KL(HeadKs,,K,,TailKs))
288289
andBool isElab(HeadKs) //Forces elaboration left-to-right. Required when KL == 'ListWrap of statements.
289290
[transition-strictness]
290291
292+
rule [elabCool-default]:
293+
(ElabK:K => .) ~> elab(_:KLabel(_,, (CHOLE => ElabK),, _))
294+
when
295+
isElab(ElabK)
296+
297+
/* todo generalized context rule. Don't work yet as we cannot have KResult in the RHS of a syntax declaration.
298+
*/
299+
/* Disadvantage of generic elab heating:
300+
heated terms oare of 2 cathegories: defaultElabChildren and naked. for naked terms we should not heat
301+
their children anymore, but should unwrap their elab() wrapper. This is accomplished well enough for the moment.
302+
*/
303+
/*context elab(KL:KLabel(HeadKs:KList,, HOLE:K,, _:KList))
304+
when
305+
defaultElabChildren(KL)
306+
//notBool customElabChildren(KL)
307+
andBool isElab(HeadKs) //Forces elaboration left-to-right. Required when KL == 'ListWrap of statements.
308+
[result('isElab`(_`)), context(elab), transition-strictness]
309+
310+
syntax ElabRes ::= TypedExp | KResult */
291311

292312
/*@ Terms that should use custom elaboration rules. For those terms:
293313
- They will not be automatically heated from their parents into the elab() state.
@@ -310,23 +330,6 @@ rule customElabChildren(KL:KLabel) =>
310330
orBool (KL ==KLabel 'NewInstance)
311331
orBool (KL ==KLabel 'QNewInstance)
312332
313-
/*@ Represents terms that shoud never be wrapped by elab() or related wrappers. They are processed to their final state
314-
in elaboration phase. Those are types names, package names, id's ad literals.
315-
*/
316-
syntax K ::= "isElabNaked" "(" K ")" [function]
317-
rule isElabNaked(K:K) =>
318-
//warning: cannot use ==Bool in the first expression - looks like isTypedExp(Qual) will not be computed
319-
(isRawVal(K) ==K true)
320-
orBool (getKLabel(K) ==KLabel 'TypeName)
321-
orBool (getKLabel(K) ==KLabel 'ClassOrInterfaceType)
322-
orBool (getKLabel(K) ==KLabel 'InterfaceType)
323-
orBool (getKLabel(K) ==KLabel 'ClassType)
324-
orBool (getKLabel(K) ==KLabel 'ArrayType)
325-
orBool (getKLabel(K) ==KLabel 'PackageName)
326-
orBool (getKLabel(K) ==KLabel 'PackageOrTypeName)
327-
orBool (getKLabel(K) ==KLabel 'Id)
328-
orBool (getKLabel(K) ==KLabel 'Lit)
329-
330333
/*@ Java KLabels that are processed by default heating/cooling rules of elaboration.
331334
All KLabels that can be part of a code block during elaboration phase,
332335
except those members of customElabChildren or isElabNaked groups.
@@ -400,11 +403,12 @@ rule defaultElabChildren(KL:KLabel) =>
400403
orBool (KL ==KLabel 'NewArray)
401404
// orBool (KL ==KLabel 'UnboundWld)
402405
orBool (KL ==KLabel 'Dim)
403-
// orBool (KL ==KLabel 'NewInstance)
404-
// orBool (KL ==KLabel 'QNewInstance)
405-
// orBool (KL ==KLabel 'Lit)
406-
// orBool (KL ==KLabel 'Class)
407-
/* orBool (KL ==KLabel 'VoidClass)*/
406+
407+
/*orBool (KL ==KLabel 'NewInstance)
408+
orBool (KL ==KLabel 'QNewInstance)
409+
orBool (KL ==KLabel 'Lit)
410+
orBool (KL ==KLabel 'Class)
411+
orBool (KL ==KLabel 'VoidClass)*/
408412
orBool (KL ==KLabel 'This)
409413
orBool (KL ==KLabel 'QThis)
410414
/*orBool (KL ==KLabel 'PackageDec)
@@ -427,14 +431,14 @@ rule defaultElabChildren(KL:KLabel) =>
427431
orBool (KL ==KLabel 'EnumDecHead)
428432
orBool (KL ==KLabel 'EnumBody)
429433
orBool (KL ==KLabel 'EnumConst)
430-
orBool (KL ==KLabel 'EnumBodyDecs)*/
431-
/*orBool (KL ==KLabel 'ConstrDec)
434+
orBool (KL ==KLabel 'EnumBodyDecs)
435+
orBool (KL ==KLabel 'ConstrDec)
432436
orBool (KL ==KLabel 'ConstrDecHead)
433-
orBool (KL ==KLabel 'ConstrBody)*/
434-
// orBool (KL ==KLabel 'AltConstrInv)
435-
// orBool (KL ==KLabel 'SuperConstrInv)
436-
// orBool (KL ==KLabel 'QSuperConstrInv)
437-
/*orBool (KL ==KLabel 'StaticInit)
437+
orBool (KL ==KLabel 'ConstrBody)
438+
orBool (KL ==KLabel 'AltConstrInv)
439+
orBool (KL ==KLabel 'SuperConstrInv)
440+
orBool (KL ==KLabel 'QSuperConstrInv)
441+
orBool (KL ==KLabel 'StaticInit)
438442
orBool (KL ==KLabel 'InstanceInit)*/
439443
orBool (KL ==KLabel 'Empty)
440444
orBool (KL ==KLabel 'Labeled)
@@ -533,6 +537,7 @@ rule defaultElabChildren(KL:KLabel) =>
533537
orBool (KL ==KLabel 'StrictFP)
534538
orBool (KL ==KLabel 'Id)*/
535539
540+
//todo elaboration-related hack - we should not have special elaboration rules for auxiliary constructs
536541
syntax K ::= auxLabelInElab( KLabel ) [function]
537542
rule auxLabelInElab(KL:KLabel) =>
538543
KL ==KLabel 'setEncloser`(_`,_`,_`)
@@ -541,18 +546,31 @@ rule auxLabelInElab(KL:KLabel) =>
541546
orBool KL ==KLabel 'stmtAndExp`(_`,_`)
542547
orBool KL ==KLabel 'toString`(_`)
543548

544-
//@ Will not match .K - is not isElabNaked. (.K) is matched by [elabDotK].
549+
/*@ Represents terms that shoud never be wrapped by elab() or related wrappers. They are processed to their final state
550+
in elaboration phase. Those are types names, package names, id's ad literals.
551+
*/
552+
syntax K ::= "isElabNaked" "(" K ")" [function]
553+
rule isElabNaked(K:K) =>
554+
//warning: cannot use ==Bool in the first expression - looks like isTypedExp(Qual) will not be computed
555+
(isRawVal(K) ==K true)
556+
orBool (getKLabel(K) ==KLabel 'TypeName)
557+
orBool (getKLabel(K) ==KLabel 'ClassOrInterfaceType)
558+
orBool (getKLabel(K) ==KLabel 'InterfaceType)
559+
orBool (getKLabel(K) ==KLabel 'ClassType)
560+
orBool (getKLabel(K) ==KLabel 'ArrayType)
561+
orBool (getKLabel(K) ==KLabel 'PackageName)
562+
orBool (getKLabel(K) ==KLabel 'PackageOrTypeName)
563+
orBool (getKLabel(K) ==KLabel 'Id)
564+
orBool (getKLabel(K) ==KLabel 'Lit)
565+
566+
/*@ The sole place where isElabNaked is used - naked terms should be automatically unwrapped from elab() wrapper.
567+
Will not match .K - is not isElabNaked. (.K) is matched by [elabDotK].
568+
*/
545569
rule [unwrapElabNaked]:
546570
elab(K:K) => K
547571
when
548572
isElabNaked(K)
549573

550-
rule [elabCool-elabRes]:
551-
(elabRes(K:K) => .) ~> elab(_:KLabel(_,, (CHOLE => elabRes(K)),, _))
552-
553-
rule [elabCoolKResult]:
554-
(KR:KResult => .) ~> elab(_:KLabel(_,, (CHOLE => KR),, _))
555-
556574
/*@ The default algorithm of transforming the term from elab to elabRes, when the children were completely elaborated.
557575
Deletes elabRes wrappers from children. This algorithm is activated when the following conditions apply:
558576
- term is not customElabChildren

0 commit comments

Comments
 (0)