Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
4378143f
F
fsharp
项目概览
dotNET Platform
/
fsharp
12 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fsharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
4378143f
编写于
6月 29, 2021
作者:
K
kerams
提交者:
GitHub
6月 29, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize interpolated string with no holes (#11632)
上级
00397560
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
71 addition
and
17 deletion
+71
-17
src/fsharp/CheckExpressions.fs
src/fsharp/CheckExpressions.fs
+25
-17
tests/FSharp.Compiler.ComponentTests/EmittedIL/StringFormatAndInterpolation.fs
....ComponentTests/EmittedIL/StringFormatAndInterpolation.fs
+32
-0
tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj
...iler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj
+1
-0
tests/fsharp/core/quotes/test.fsx
tests/fsharp/core/quotes/test.fsx
+13
-0
未找到文件。
src/fsharp/CheckExpressions.fs
浏览文件 @
4378143f
...
@@ -6751,27 +6751,35 @@ and TcInterpolatedStringExpr cenv overallTy env m tpenv (parts: SynInterpolatedS
...
@@ -6751,27 +6751,35 @@ and TcInterpolatedStringExpr cenv overallTy env m tpenv (parts: SynInterpolatedS
UnifyTypes cenv env m printerTupleTy printerTupleTyRequired
UnifyTypes cenv env m printerTupleTy printerTupleTyRequired
// Type check the expressions filling the holes
if List.isEmpty synFillExprs then
let flexes = argTys |> List.map (fun _ -> false)
let str = mkString g m printfFormatString
let fillExprs, tpenv = TcExprs cenv env m tpenv flexes argTys synFillExprs
let fillExprsBoxed = (argTys, fillExprs) ||> List.map2 (mkCallBox g m)
if isString then
str, tpenv
let argsExpr = mkArray (g.obj_ty, fillExprsBoxed, m)
let percentATysExpr =
if percentATys.Length = 0 then
mkNull m (mkArrayType g g.system_Type_ty)
else
else
let tyExprs = percentATys |> Array.map (mkCallTypeOf g m) |> Array.toList
mkCallNewFormat cenv.g m printerTy printerArgTy printerResidueTy printerResultTy printerTupleTy str, tpenv
mkArray (g.system_Type_ty, tyExprs, m)
else
// Type check the expressions filling the holes
let flexes = argTys |> List.map (fun _ -> false)
let fillExprs, tpenv = TcExprs cenv env m tpenv flexes argTys synFillExprs
let fmtExpr = MakeMethInfoCall cenv.amap m newFormatMethod [] [mkString g m printfFormatString; argsExpr; percentATysExpr]
let fillExprsBoxed = (argTys, fillExprs) ||> List.map2 (mkCallBox g m)
if isString then
let argsExpr = mkArray (g.obj_ty, fillExprsBoxed, m)
// Make the call to sprintf
let percentATysExpr =
mkCall_sprintf g m printerTy fmtExpr [], tpenv
if percentATys.Length = 0 then
else
mkNull m (mkArrayType g g.system_Type_ty)
fmtExpr, tpenv
else
let tyExprs = percentATys |> Array.map (mkCallTypeOf g m) |> Array.toList
mkArray (g.system_Type_ty, tyExprs, m)
let fmtExpr = MakeMethInfoCall cenv.amap m newFormatMethod [] [mkString g m printfFormatString; argsExpr; percentATysExpr]
if isString then
// Make the call to sprintf
mkCall_sprintf g m printerTy fmtExpr [], tpenv
else
fmtExpr, tpenv
// The case for $"..." used as type FormattableString or IFormattable
// The case for $"..." used as type FormattableString or IFormattable
| Choice2Of2 createFormattableStringMethod ->
| Choice2Of2 createFormattableStringMethod ->
...
...
tests/FSharp.Compiler.ComponentTests/EmittedIL/StringFormatAndInterpolation.fs
0 → 100644
浏览文件 @
4378143f
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace
FSharp
.
Compiler
.
ComponentTests
.
EmittedIL
open
Xunit
open
FSharp
.
Test
.
Utilities
.
Compiler
module
``StringFormatAndInterpolation``
=
[<
Fact
>]
let
``Interpolated string with no holes is reduced to a string or simple format when used in printf``
()
=
FSharp
"""
module StringFormatAndInterpolation
let stringOnly () = $"
no
hole
"
let printed () = printf $"
printed
no
hole
"
"""
|>
compile
|>
shouldSucceed
|>
verifyIL
[
"""
IL_0000: ldstr "
no
hole
"
IL_0005: ret"""
"""
IL_0000: ldstr "
printed
no
hole
"
IL_0005: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5<class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit>::.ctor(string)
IL_000a: stloc.0
IL_000b: call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()
IL_0010: ldloc.0
IL_0011: call !!0 [FSharp.Core]Microsoft.FSharp.Core.PrintfModule::PrintFormatToTextWriter<class [FSharp.Core]Microsoft.FSharp.Core.Unit>(class [runtime]System.IO.TextWriter,
class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4<!!0,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit>)
IL_0016: pop
IL_0017: ret"""
]
tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj
浏览文件 @
4378143f
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
<Compile
Include=
"EmittedIL\Literals.fs"
/>
<Compile
Include=
"EmittedIL\Literals.fs"
/>
<Compile
Include=
"EmittedIL\Misc.fs"
/>
<Compile
Include=
"EmittedIL\Misc.fs"
/>
<Compile
Include=
"EmittedIL\SkipLocalsInit.fs"
/>
<Compile
Include=
"EmittedIL\SkipLocalsInit.fs"
/>
<Compile
Include=
"EmittedIL\StringFormatAndInterpolation.fs"
/>
<Compile
Include=
"EmittedIL\TailCalls.fs"
/>
<Compile
Include=
"EmittedIL\TailCalls.fs"
/>
<Compile
Include=
"EmittedIL\TupleElimination.fs"
/>
<Compile
Include=
"EmittedIL\TupleElimination.fs"
/>
<Compile
Include=
"ErrorMessages\TypeEqualsMissingTests.fs"
/>
<Compile
Include=
"ErrorMessages\TypeEqualsMissingTests.fs"
/>
...
...
tests/fsharp/core/quotes/test.fsx
浏览文件 @
4378143f
...
@@ -4119,6 +4119,19 @@ module CheckEliminatedConstructs =
...
@@ -4119,6 +4119,19 @@ module CheckEliminatedConstructs =
"""IfThenElse (Call (None, op_Equality, [ValueWithName ([||], ts), Value (<null>)]),
"""IfThenElse (Call (None, op_Equality, [ValueWithName ([||], ts), Value (<null>)]),
Value (true), Value (false))"""
Value (true), Value (false))"""
module
Interpolation
=
let
interpolatedNoHoleQuoted
=
<@
$
"abc"
@>
let
actual1
=
interpolatedNoHoleQuoted
.
ToString
()
checkStrings
"brewbreebrwhat1"
actual1
"""Value ("
abc
")"""
let
interpolatedWithLiteralQuoted
=
<@
$
"abc {1} def"
@>
let
actual2
=
interpolatedWithLiteralQuoted
.
ToString
()
checkStrings
"brewbreebrwhat2"
actual2
"""Call (None, PrintFormatToString,
[NewObject (PrintfFormat`5, Value ("
abc
%
P
()
def
"),
NewArray (Object, Call (None, Box, [Value (1)])),
Value (<null>))])"""
module
TestAssemblyAttributes
=
module
TestAssemblyAttributes
=
let
attributes
=
System
.
Reflection
.
Assembly
.
GetExecutingAssembly
()
.
GetCustomAttributes
(
false
)
let
attributes
=
System
.
Reflection
.
Assembly
.
GetExecutingAssembly
()
.
GetCustomAttributes
(
false
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录