Skip to content

Commit abb8c55

Browse files
KJ-15 Eliminated the rule unwrapElabNaked - replaced with context rule.
The logic of literals had to be changed slightly. I had to review what should be wrapped into elab and what should not.
1 parent 55a0fe7 commit abb8c55

4 files changed

Lines changed: 35 additions & 28 deletions

File tree

semantics/api-core.k

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ rule [object-getClass-on-object]:
8484
invokeImpl(
8585
methodClosure(_,_,_,_,_,_, 'NoMethodBody(_))::methodType(sig(MethodName:Id, _),_), OL:Int,
8686
'ListWrap(.KList)
87-
) => 'Lit('Class(T))
87+
) => elab('Lit('Class(T)))
8888
...
8989
</k>
9090
<store>
@@ -99,15 +99,15 @@ rule [object-getClass-on-String]:
9999
invokeImpl(
100100
methodClosure(_,_,_,_,_,_, 'NoMethodBody(_))::methodType(sig(MethodName:Id, _),_), Str:String::rtString,
101101
'ListWrap(.KList)
102-
) => 'Lit('Class(rtString))
102+
) => elab('Lit('Class(rtString)))
103103
when
104104
Id2String(MethodName) ==String "getClass"
105105

106106
rule [object-getClass-on-array]:
107107
invokeImpl(
108108
methodClosure(_,_,_,_,_,_, 'NoMethodBody(_))::methodType(sig(MethodName:Id, _),_), arrayRef(_,_,_)::ArrT:Type,
109109
'ListWrap(.KList)
110-
) => 'Lit('Class(ArrT))
110+
) => elab('Lit('Class(ArrT)))
111111
when
112112
Id2String(MethodName) ==String "getClass"
113113

semantics/api-threads.k

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ rule [synchronized-method-inst-desugar]:
108108
rule [synchronized-method-static-desugar]:
109109
<k>
110110
storeMethod(_, staticCT, _, (true => false)::bool, _,_,
111-
Body:K => 'Synchronized('Lit('Class(Class)),, Body),
111+
Body:K => 'Synchronized(elab('Lit('Class(Class))),, Body),
112112
_)
113113
...
114114
</k>

semantics/elaborate-blocks.k

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,15 @@ The attribute [transition-strictness] is used as transition attribute for testin
280280
This is a rule that may lead to unexpected nondeterminism if it is wrongly implemented.
281281
In order to expose incorrect nondeterminism we need to model-check a program that exposes the nondeterminism.
282282
*/
283-
rule [elabHeatDefault]:
283+
rule [elabHeat-default]:
284284
(. => elab(K)) ~> elab(KL:KLabel(HeadKs:KList,, (K:K => CHOLE),, TailKs:KList))
285285
when
286286
defaultElabChildren(KL)
287287
//notBool customElabChildren(KL)
288288
andBool notBool isElab(K)
289+
andBool notBool isElabNaked(K)
289290
andBool isElab(HeadKs) //Forces elaboration left-to-right. Required when KL == 'ListWrap of statements.
290-
[transition-strictness]
291+
[transition-strictness]
291292
292293
rule [elabCool-default]:
293294
(ElabK:K => .) ~> elab(_:KLabel(_,, (CHOLE => ElabK),, _))
@@ -460,11 +461,11 @@ rule defaultElabChildren(KL:KLabel) =>
460461
orBool (KL ==KLabel 'Throw)
461462
orBool (KL ==KLabel 'Synchronized)
462463
orBool (KL ==KLabel 'Try)
463-
// orBool (KL ==KLabel 'Catch)
464-
// orBool (KL ==KLabel 'LocalVarDecStm)
465-
// orBool (KL ==KLabel 'LocalVarDec)
466-
// orBool (KL ==KLabel 'Block)
467-
// orBool (KL ==KLabel 'ClassDecStm)
464+
/*orBool (KL ==KLabel 'Catch)
465+
orBool (KL ==KLabel 'LocalVarDecStm)
466+
orBool (KL ==KLabel 'LocalVarDec)
467+
orBool (KL ==KLabel 'Block)
468+
orBool (KL ==KLabel 'ClassDecStm)*/
468469
/*orBool (KL ==KLabel 'MethodDec)
469470
orBool (KL ==KLabel 'MethodDecHead)
470471
orBool (KL ==KLabel 'DeprMethodDecHead)
@@ -494,8 +495,8 @@ rule defaultElabChildren(KL:KLabel) =>
494495
// orBool (KL ==KLabel 'TypeName)
495496
orBool (KL ==KLabel 'ExprName)
496497

497-
orBool auxLabelInElab(KL)
498498
orBool (KL ==KLabel 'MethodName)
499+
orBool auxLabelInElab(KL)
499500
/*orBool (KL ==KLabel 'PackageOrTypeName)
500501
orBool (KL ==KLabel 'TypeArgs)
501502
orBool (KL ==KLabel 'TypeArgs)
@@ -546,8 +547,18 @@ rule auxLabelInElab(KL:KLabel) =>
546547
orBool KL ==KLabel 'stmtAndExp`(_`,_`)
547548
orBool KL ==KLabel 'toString`(_`)
548549

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.
550+
/*@ elabHeat-naked-children
551+
Since a naked term is always computed int oa KResult during elaboration,
552+
we can use a simple context rule to heat such terms.
553+
*/
554+
context elab(KL:KLabel(_:KList,, HOLE,, _:KList))
555+
when
556+
defaultElabChildren(KL)
557+
andBool isElabNaked(HOLE)
558+
559+
/*@ Naked terms are those that should be computed directly into KResult during elaboration.
560+
Those are literals, types and packages. They are heated "as is", without being wrapped into elab().
561+
An exception is the class literal that is not executed during elaboration.
551562
*/
552563
syntax K ::= "isElabNaked" "(" K ")" [function]
553564
rule isElabNaked(K:K) =>
@@ -561,15 +572,10 @@ rule isElabNaked(K:K) =>
561572
orBool (getKLabel(K) ==KLabel 'PackageName)
562573
orBool (getKLabel(K) ==KLabel 'PackageOrTypeName)
563574
orBool (getKLabel(K) ==KLabel 'Id)
564-
orBool (getKLabel(K) ==KLabel 'Lit)
575+
orBool (getKLabel(K) ==KLabel 'Lit andBool getInnerKLabel(K) =/=KLabel 'Class)
565576

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-
*/
569-
rule [unwrapElabNaked]:
570-
elab(K:K) => K
571-
when
572-
isElabNaked(K)
577+
syntax KLabel ::= "getInnerKLabel" "(" K ")" [function]
578+
rule getInnerKLabel(_:KLabel(KL:KLabel(_))) => KL
573579

574580
/*@ The default algorithm of transforming the term from elab to elabRes, when the children were completely elaborated.
575581
Deletes elabRes wrappers from children. This algorithm is activated when the following conditions apply:
@@ -1238,13 +1244,15 @@ rule [elab-QNewInstance]:
12381244
rule [elabInstanceOf]:
12391245
elabDispose('InstanceOf(TE:TypedExp,, RT2:RefType)) => elabRes('InstanceOf(TE,, RT2) :: bool)
12401246
1241-
context 'Lit('Class(HOLE))
1247+
//@ Class literal types are heated by this rule.
1248+
context elab('Lit('Class(HOLE)))
12421249
12431250
rule [elabLitClass]:
1244-
'Lit('Class(T:Type)) => elabRes('Lit('Class(T:Type)) :: class String2Id("java.lang.Class"))
1251+
elab('Lit('Class(T:Type))) => elabRes('Lit('Class(T:Type)) :: class String2Id("java.lang.Class"))
12451252
12461253
rule [elabArrayAccess]:
1247-
elabDispose('ArrayAccess(TargetExp:K::arrayOf T:Type,, IndexTE:TypedExp)) => elabRes('ArrayAccess(TargetExp::arrayOf T,, IndexTE) :: T)
1254+
elabDispose('ArrayAccess(TargetExp:K::arrayOf T:Type,, IndexTE:TypedExp))
1255+
=> elabRes('ArrayAccess(TargetExp::arrayOf T,, IndexTE) :: T)
12481256
12491257
rule [elabArrayLength]:
12501258
elabDispose('Field(Qual:K :: arrayOf T:Type,, X:Id))

semantics/literals.k

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module LITERALS
88
imports CORE
99
imports AUX-STRINGS
1010
imports PRIMITIVE-TYPES
11-
imports ELABORATE-BLOCKS //for elab(), should disappear after semantics separation
1211

1312
//@ \subsection{Auxiliary constructs}
1413

@@ -153,9 +152,9 @@ rule 'Lit('Char('UnicodeEscape(_:K,, I1:Int,, I2:Int,, I3:Int,, I4:Int)))
153152
//@ \subsection{String literals}
154153
155154
rule 'Lit('String('ListWrap(K1:K,, K2:K,, Ks:KList)))
156-
=> elab('Plus('Lit('String('ListWrap(K1))),,
155+
=> 'Plus('Lit('String('ListWrap(K1))),,
157156
'Lit('String('ListWrap(K2,, Ks)))
158-
))
157+
) :: rtString
159158
160159
rule 'Lit('String('ListWrap('Chars(Str:String)))) => Str
161160

0 commit comments

Comments
 (0)