Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ec23c1

Browse files
committed
fix 212 - record initialization order
1 parent1251430 commit2ec23c1

File tree

2 files changed

+217
-41
lines changed

2 files changed

+217
-41
lines changed

‎src/fsharp/tastops.fs‎

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5807,51 +5807,41 @@ let permute (sigma:int[]) (data:'T[]) =
58075807

58085808
let recexistsR a b pred=if a<=bthen pred a|| existsR(a+1) b predelsefalse
58095809

5810-
letmapFoldListi f z xs=
5811-
let recfmapi f i z l=
5812-
match lwith
5813-
|[]-> z,[]
5814-
| x::xs->letz,x= f i z x
5815-
letz,xs= fmapi f(i+1) z xs
5816-
z,x::xs
5817-
fmapi f0 z xs
5818-
5819-
/// Given expr = xi = [| x0; ... xN |]
5820-
/// Given sigma a permutation to apply to the xi.
5821-
/// Return (bindings',expr') such that:
5822-
/// (a) xi are permutated under sigma, xi -> position sigma(i).
5823-
///------
5824-
/// Motivation:
5825-
/// opt.fs - put record field assignments in order under known effect information
5826-
/// ilxgen.fs - put record field assignments in order if necessary (no optimisations)
5827-
/// under unknown-effect information.
5828-
letpermuteExpr(sigma:int[])(expr:Expr[])(typ:TType[])(names:string[])=
5810+
// Given a permutation for record fields, work out the highest entry that we must lift out
5811+
// of a record initialization. Lift out xi if xi goes to position that will be preceded by an expr with an effect
5812+
// that originally followed xi. If one entry gets lifted then everything before it also gets lifted.
5813+
letliftAllBefore sigma=
58295814
letinvSigma= inversePerm sigma
5830-
letliftPosition i=
5831-
// Lift out xi if
5832-
// LC2: xi goes to position that will be preceded by
5833-
// an expr with an effect that originally followed xi
5834-
leti'= sigma.[i]
5835-
existsR0(i'-1)(fun j'-> invSigma.[j']> i)
5836-
5837-
letrewrite i rbinds(xi:Expr)=
5838-
if liftPosition ithen
5839-
lettmpv,tmpe= mkCompGenLocal xi.Range names.[i] typ.[i]
5840-
letbind= mkCompGenBind tmpv xi
5841-
bind:: rbinds,tmpe
5815+
5816+
letlifted=
5817+
[for iin0.. sigma.Length-1do
5818+
leti'= sigma.[i]
5819+
if existsR0(i'-1)(fun j'-> invSigma.[j']> i)then
5820+
yield i]
5821+
5822+
if lifted.IsEmptythen0else List.max lifted+1
5823+
5824+
5825+
/// Put record field assignments in order.
5826+
//
5827+
letpermuteExprList(sigma:int[])(exprs:Expr list)(typ:TType list)(names:string list)=
5828+
lettyp,names=(Array.ofList typ, Array.ofList names)
5829+
5830+
letliftLim= liftAllBefore sigma
5831+
5832+
letrewrite rbinds(i,expri:Expr)=
5833+
if i< liftLimthen
5834+
lettmpvi,tmpei= mkCompGenLocal expri.Range names.[i] typ.[i]
5835+
letbindi= mkCompGenBind tmpvi expri
5836+
tmpei, bindi:: rbinds
58425837
else
5843-
rbinds,xi
5838+
expri, rbinds
58445839

5845-
letxis= Array.toList expr
5846-
letrbinds,xis= mapFoldListi rewrite[] xis
5847-
letbinds= List.rev rbinds
5848-
letexpr= permute sigma(Array.ofList xis)
5849-
binds,expr
5840+
letnewExprs,reversedBinds= List.mapFold rewrite[](exprs|> List.mapi(fun i x->(i,x)))
5841+
letbinds= List.rev reversedBinds
5842+
letreorderedExprs= permute sigma(Array.ofList newExprs)
5843+
binds,Array.toList reorderedExprs
58505844

5851-
letpermuteExprList(sigma:int array)(expr:Expr list)(typ:TType list)(names:string list)=
5852-
letbinds,expr= permuteExpr sigma(Array.ofList expr)(Array.ofList typ)(Array.ofList names)
5853-
binds,Array.toList expr
5854-
58555845
//-------------------------------------------------------------------------
58565846
// Build record expressions...
58575847
//-------------------------------------------------------------------------

‎tests/fsharp/core/apporder/test.fsx‎

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,192 @@ module MemberAppOrder =
930930
check"cwkneccewi" state[3;2;5;4]
931931
check"nvroirv"(sprintf"%d%d%d%d%d" foo.A foo.B foo.X foo.Y foo.Z)"4 5 3 2 99"
932932

933+
typeRecordWithInts=
934+
{ A:int
935+
B:int
936+
C:int}
937+
938+
moduleOrderOfRecordInitialisation=
939+
940+
letexpected=
941+
{ A=1
942+
B=2
943+
C=3}
944+
945+
letShouldInitialzeInGivenOrder1=
946+
letorder= ref""
947+
letactual=
948+
{ A=let_= order:=!order+"1" in 1
949+
B=let_= order:=!order+"2" in 2
950+
C=let_= order:=!order+"3" in 3}
951+
952+
check"cnclewlecp2" expected actual
953+
check"ceiewoi""123"!order
954+
955+
letShouldInitialzeInGivenOrder2=
956+
letorder= ref""
957+
letactual=
958+
{ A=let_= order:=!order+"1" in 1
959+
C=let_= order:=!order+"2" in 3
960+
B=let_= order:=!order+"3" in 2}
961+
962+
check"cd33289e0ewn1" expected actual
963+
check"ewlknewv90we2""123"!order
964+
965+
letShouldInitialzeInGivenOrder3=
966+
letorder= ref""
967+
letactual=
968+
{ B=let_= order:=!order+"1" in 2
969+
A=let_= order:=!order+"2" in 1
970+
C=let_= order:=!order+"3" in 3}
971+
972+
check"cewekcjnwe3" expected actual
973+
check"cewekcjnwe4""123"!order
974+
975+
976+
letShouldInitialzeInGivenOrder4=
977+
letorder= ref""
978+
letactual=
979+
{ B=let_= order:=!order+"1" in 2
980+
C=let_= order:=!order+"2" in 3
981+
A=let_= order:=!order+"3" in 1}
982+
983+
check"cewekcjnwe5" expected actual
984+
check"cewekcjnwe6""123"!order
985+
986+
987+
letShouldInitialzeInGivenOrder5=
988+
letorder= ref""
989+
letactual=
990+
{ C=let_= order:=!order+"1" in 3
991+
A=let_= order:=!order+"2" in 1
992+
B=let_= order:=!order+"3" in 2}
993+
994+
check"cewekcjnwe7" expected actual
995+
check"cewekcjnwe8""123"!order
996+
997+
998+
letShouldInitialzeInGivenOrder6=
999+
letorder= ref""
1000+
letactual=
1001+
{ C=let_= order:=!order+"1" in 3
1002+
B=let_= order:=!order+"2" in 2
1003+
A=let_= order:=!order+"3" in 1}
1004+
1005+
check"cewekcjnwe9" expected actual
1006+
check"cewekcjnwe10""123"!order
1007+
1008+
1009+
typeRecordWithDifferentTypes=
1010+
{ A:int
1011+
B:string
1012+
C:float
1013+
D:RecordWithInts}
1014+
1015+
1016+
moduleRecordInitialisationWithDifferentTxpes=
1017+
1018+
letexpected=
1019+
{ A=1
1020+
B="2"
1021+
C=3.0
1022+
D=
1023+
{ A=4
1024+
B=5
1025+
C=6}}
1026+
1027+
1028+
letShouldInitialzeInGivenOrder1=
1029+
letorder= ref""
1030+
letactual=
1031+
{ A=let_= order:=!order+"1" in 1
1032+
B=let_= order:=!order+"2" in"2"
1033+
C=let_= order:=!order+"3" in 3.0
1034+
D=let_= order:=!order+"4" in
1035+
{ A=let_= order:=!order+"5" in 4
1036+
B=let_= order:=!order+"6" in 5
1037+
C=let_= order:=!order+"7" in 6}}
1038+
1039+
check"cewekcjnwe11" expected actual
1040+
check"cewekcjnwe12""1234567"!order
1041+
1042+
1043+
letShouldInitialzeInGivenOrder2=
1044+
letorder= ref""
1045+
letactual=
1046+
{ A=let_= order:=!order+"1" in 1
1047+
C=let_= order:=!order+"2" in 3.0
1048+
D=let_= order:=!order+"3" in
1049+
{ A=let_= order:=!order+"4" in 4
1050+
B=let_= order:=!order+"5" in 5
1051+
C=let_= order:=!order+"6" in 6}
1052+
1053+
B=let_= order:=!order+"7"in"2"}
1054+
1055+
check"cewekcjnwe13" expected actual
1056+
check"cewekcjnwe14""1234567"!order
1057+
1058+
1059+
letShouldInitialzeInGivenOrder3=
1060+
letorder= ref""
1061+
letactual=
1062+
{ A=let_= order:=!order+"1" in 1
1063+
C=let_= order:=!order+"2" in 3.0
1064+
B=let_= order:=!order+"3" in"2"
1065+
D=let_= order:=!order+"4" in
1066+
{ A=let_= order:=!order+"5" in 4
1067+
B=let_= order:=!order+"6" in 5
1068+
C=let_= order:=!order+"7" in 6}}
1069+
1070+
check"cewekcjnwe15" expected actual
1071+
check"cewekcjnwe16""1234567"!order
1072+
1073+
1074+
1075+
letShouldInitialzeInGivenOrder4=
1076+
letorder= ref""
1077+
letactual=
1078+
{ B=let_= order:=!order+"1" in"2"
1079+
A=let_= order:=!order+"2" in 1
1080+
C=let_= order:=!order+"3" in 3.0
1081+
D=let_= order:=!order+"4" in
1082+
{ A=let_= order:=!order+"5" in 4
1083+
B=let_= order:=!order+"6" in 5
1084+
C=let_= order:=!order+"7" in 6}}
1085+
1086+
check"cewekcjnwe17" expected actual
1087+
check"cewekcjnwe18""1234567"!order
1088+
1089+
1090+
letShouldInitialzeInGivenOrder5=
1091+
letorder= ref""
1092+
letactual=
1093+
{ D=let_= order:=!order+"1" in
1094+
{ A=let_= order:=!order+"2" in 4
1095+
B=let_= order:=!order+"3" in 5
1096+
C=let_= order:=!order+"4" in 6}
1097+
B=let_= order:=!order+"5"in"2"
1098+
C=let_= order:=!order+"6"in3.0
1099+
A=let_= order:=!order+"7"in1}
1100+
1101+
check"cewekcjnwe19" expected actual
1102+
check"cewekcjnwe20""1234567"!order
1103+
1104+
1105+
letShouldInitialzeInGivenOrder6=
1106+
letorder= ref""
1107+
letactual=
1108+
{ D=let_= order:=!order+"1" in
1109+
{ A=let_= order:=!order+"2" in 4
1110+
B=let_= order:=!order+"3" in 5
1111+
C=let_= order:=!order+"4" in 6}
1112+
A=let_= order:=!order+"5"in1
1113+
B=let_= order:=!order+"6"in"2"
1114+
C=let_= order:=!order+"7"in3.0}
1115+
1116+
check"cewekcjnwe21" expected actual
1117+
check"cewekcjnwe22""1234567"!order
1118+
9331119
letaa=
9341120
if!failuresthen(stdout.WriteLine"Test Failed"; exit1)
9351121
else(stdout.WriteLine"Test Passed";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp