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

Commitb1c03b6

Browse files
andrewjkennedylatkin
andrewjkennedy
authored andcommitted
Pickling of metadata for units: need to ensure that integer exponents are pickled in a form compatible with F# 3.x tools.
fixesdotnet#69closesdotnet#72commit a56686150e512f846d3548eb28161d59d6e9ee42Merge:09ad755e4cf4a2Author: latkin <latkin@microsoft.com>Date: Thu Jan 22 11:55:47 2015 -0800 Merge branch 'fsharp4' ofhttps://github.com/andrewjkennedy/visualfsharp into andrewjkennedy-fsharp4commite4cf4a2Author: andrewjkennedy <akenn@microsoft.com>Date: Wed Jan 21 11:21:19 2015 +0000 Small cleanup of units picklingcommitdb6643aAuthor: andrewjkennedy <akenn@microsoft.com>Date: Wed Jan 21 10:34:07 2015 +0000 Pickling of units-of-measure: * Comments * Factored code a bit bettercommit77ba222Author: andrewjkennedy <akenn@microsoft.com>Date: Tue Jan 20 15:59:54 2015 +0000 Pickling of metadata for units: need to ensure that integer exponents are pickled in a form compatible with F# 3.x tools. This is issuedotnet#69 on github.
1 parent09ad755 commitb1c03b6

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

‎src/fsharp/pickle.fs‎

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,17 +1409,60 @@ let u_trait st =
14091409
TTrait(a,b,c,d,e,ref f)
14101410

14111411
#if INCLUDE_METADATA_WRITER
1412+
14121413
letp_rational q st= p_int32(GetNumerator q) st; p_int32(GetDenominator q) st
14131414

1414-
let recp_measure_expr unt st=
1415-
letunt= stripUnitEqnsAuxfalse unt
1416-
match untwith
1417-
| MeasureCon tcref-> p_byte0 st; p_tcref"measure" tcref st
1418-
| MeasureInv x-> p_byte1 st; p_measure_expr x st
1419-
| MeasureProd(x1,x2)-> p_byte2 st; p_measure_expr x1 st; p_measure_expr x2 st
1420-
| MeasureVar(v)-> p_byte3 st; p_tpref v st
1421-
| MeasureOne-> p_byte4 st
1422-
| MeasureRationalPower(x,q)-> p_byte5 st; p_measure_expr x st; p_rational q st
1415+
letp_measure_con tcref st= p_byte0 st; p_tcref"measure" tcref st
1416+
letp_measure_var v st= p_byte3 st; p_tpref v st
1417+
letp_measure_one= p_byte4
1418+
1419+
// Pickle a unit-of-measure variable or constructor
1420+
letp_measure_varcon unt st=
1421+
match untwith
1422+
| MeasureCon tcref-> p_measure_con tcref st
1423+
| MeasureVar v-> p_measure_var v st
1424+
|_-> pfailwith st("p_measure_varcon: expected measure variable or constructor")
1425+
1426+
// Pickle a positive integer power of a unit-of-measure variable or constructor
1427+
let recp_measure_pospower unt n st=
1428+
if n=1
1429+
then p_measure_varcon unt st
1430+
else p_byte2 st; p_measure_varcon unt st; p_measure_pospower unt(n-1) st
1431+
1432+
// Pickle a non-zero integer power of a unit-of-measure variable or constructor
1433+
letp_measure_intpower unt n st=
1434+
if n<0
1435+
then p_byte1 st; p_measure_pospower unt(-n) st
1436+
else p_measure_pospower unt n st
1437+
1438+
// Pickle a rational power of a unit-of-measure variable or constructor
1439+
let recp_measure_power unt q st=
1440+
if q= ZeroRationalthen p_measure_one st
1441+
elif GetDenominator q=1
1442+
then p_measure_intpower unt(GetNumerator q) st
1443+
else p_byte5 st; p_measure_varcon unt st; p_rational q st
1444+
1445+
// Pickle a normalized unit-of-measure expression
1446+
// Normalized means of the form cv1 ^ q1 * ... * cvn ^ qn
1447+
// where q1, ..., qn are non-zero, and cv1, ..., cvn are distinct unit-of-measure variables or constructors
1448+
let recp_normalized_measure unt st=
1449+
letunt= stripUnitEqnsAuxfalse unt
1450+
match untwith
1451+
| MeasureCon tcref-> p_measure_con tcref st
1452+
| MeasureInv x-> p_byte1 st; p_normalized_measure x st
1453+
| MeasureProd(x1,x2)-> p_byte2 st; p_normalized_measure x1 st; p_normalized_measure x2 st
1454+
| MeasureVar v-> p_measure_var v st
1455+
| MeasureOne-> p_measure_one st
1456+
| MeasureRationalPower(x,q)-> p_measure_power x q st
1457+
1458+
// By normalizing the unit-of-measure and treating integer powers as a special case,
1459+
// we ensure that the pickle format for rational powers of units (byte 5 followed by
1460+
// numerator and denominator) is used only when absolutely necessary, maintaining
1461+
// compatibility of formats with versions prior to F# 4.0.
1462+
//
1463+
// See https://github.com/Microsoft/visualfsharp/issues/69
1464+
letp_measure_expr unt st= p_normalized_measure(normalizeMeasure st.oglobals unt) st
1465+
14231466
#endif
14241467

14251468
letu_rational st=

‎src/fsharp/tastops.fsi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ val ListMeasureConOccsWithNonZeroExponents : TcGlobals -> bool -> MeasureExpr ->
541541
valProdMeasures:MeasureExpr list->MeasureExpr
542542
valMeasureVarExponent:Typar->MeasureExpr->Rational
543543
valMeasureConExponent:TcGlobals->bool->TyconRef->MeasureExpr->Rational
544+
valnormalizeMeasure:TcGlobals->MeasureExpr->MeasureExpr
545+
544546

545547
//-------------------------------------------------------------------------
546548
// Members

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp