Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dsyme tuple spike #6

Merged
merged 6 commits into from
Jul 19, 2016
Merged

Dsyme tuple spike #6

merged 6 commits into from
Jul 19, 2016

Conversation

KevinRansom
Copy link

Don,

I tried to emit the right code for reading from a struct tuple field however, it is not correct. Can you take a look and let me know what I did wrong. I think the issue is at tastops.fs around line 7830.

let struct (one,_) = struct (2, 4)
0

This code:
when compiled generates this error

c:\projects\structtuples>basictuple.exe

Unhandled Exception: System.TypeLoadException: Could not load type 'System.ValueTuple`2' from assembly 'basictuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at <StartupCode$basictuple>.$Basictuple.main@()

c:\projects\structtuples>

Note the System.ValueTuple dll exists in the execution directory


let mkGetTupleItemN g m n (typ:ILType) isStruct te retty =
if isStruct then
mkAsmExpr([mkNormalLdfld (mkILFieldSpecForTupleItem typ n) ],[],[],[retty],m)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not using te (the expression for the object from which you're loading the field) in the first branch

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

te doesn't make a difference.

@dsyme
Copy link
Owner

dsyme commented Jul 11, 2016

@KevinRansom I left one comment, though I'm not sure that explains the error message above. Run peverify.exe on the generated code?

@KevinRansom
Copy link
Author

c:\projects\structtuples>"c:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\PEVerify.exe" basictuple.exe

Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.0
Copyright (c) Microsoft Corporation. All rights reserved.

[IL]: Error: [c:\projects\structtuples\basictuple.exe : <StartupCode$basictuple>.$Basictuple::main@][offset 0x00000021] Unable to resolve token.
1 Error(s) Verifying basictuple.exe

c:\projects\structtuples>

@dsyme
Copy link
Owner

dsyme commented Jul 11, 2016

Use ILDASM /OUT=out.il and paste the IL in a gist, maybe we'll spot something

@KevinRansom
Copy link
Author

@dsyme
Copy link
Owner

dsyme commented Jul 11, 2016

This ldfld instruction looks like it is missing a generic instantiation on the ValueTuple type. Looking at the generating code I didn't immediately spot why

https://gist.github.com/KevinRansom/014a53b4f2f4426f4ae46f78545d7062#file-basictuple-il-L153

@KevinRansom
Copy link
Author

https://gist.github.com/KevinRansom/014a53b4f2f4426f4ae46f78545d7062

From: Don Syme [mailto:notifications@github.com]
Sent: Monday, July 11, 2016 7:53 AM
To: dsyme/visualfsharp visualfsharp@noreply.github.com
Cc: Kevin Ransom Kevin.Ransom@microsoft.com; Mention mention@noreply.github.com
Subject: Re: [dsyme/visualfsharp] Dsyme tuple spike (#6)

Use ILDASM /OUT=out.il and paste the IL in a gist, maybe we'll spot something


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//pull/6#issuecomment-231758674, or mute the threadhttps://github.com/notifications/unsubscribe/AE76FjkIxD9WmhbUL-CF_EmTHsxlNQh1ks5qUljngaJpZM4JJZyI.

@KevinRansom
Copy link
Author

Yes … that was my suspicion too and I can’t figure out the right Voodoo to make it work.

From: Don Syme [mailto:notifications@github.com]
Sent: Monday, July 11, 2016 8:05 AM
To: dsyme/visualfsharp visualfsharp@noreply.github.com
Cc: Kevin Ransom Kevin.Ransom@microsoft.com; Mention mention@noreply.github.com
Subject: Re: [dsyme/visualfsharp] Dsyme tuple spike (#6)

This ldfld instruction looks like it is missing a generic instantiation on the ValueTuple type. Looking at the generating code I didn't immediately spot why

https://gist.github.com/KevinRansom/014a53b4f2f4426f4ae46f78545d7062#file-basictuple-il-L153https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fgist.github.com%2fKevinRansom%2f014a53b4f2f4426f4ae46f78545d7062%23file-basictuple-il-L153&data=01%7c01%7cKevin.Ransom%40microsoft.com%7c3970a3c5b6ae4e05ea3e08d3a99ce963%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=0NSi7iuTYddA1oxRVXOC9s56J1ZBj%2bbTDDjbWub%2fKDM%3d


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//pull/6#issuecomment-231762365, or mute the threadhttps://github.com/notifications/unsubscribe/AE76Fn5lx5Wyp_S3geufCrIhkV4E7RJtks5qUluzgaJpZM4JJZyI.

@dsyme
Copy link
Owner

dsyme commented Jul 11, 2016

It feels like the lack of a type instantiation must be flowing in from somewhere earlier (I checked we can emit references to IL fields in generic IL classes ok).

At this stage I'd probably use a debug build with devenv /debugexe fsc.exe test.fs and put a breakpoint in the struct cases of the code generation and double check the instantiation is missing. If so, then try to track backwards for where it got lost.

@KevinRansom
Copy link
Author

Okay I will give that a try.

Thanks Don

From: Don Syme [mailto:notifications@github.com]
Sent: Monday, July 11, 2016 8:21 AM
To: dsyme/visualfsharp visualfsharp@noreply.github.com
Cc: Kevin Ransom Kevin.Ransom@microsoft.com; Mention mention@noreply.github.com
Subject: Re: [dsyme/visualfsharp] Dsyme tuple spike (#6)

It feels like the lack of a type instantiation must be flowing in from somewhere earlier (I checked we can emit references to IL fields in generic IL classes ok).

At this stage I'd probably use a debug build with devenv /debugexe fsc.exe test.fs and put a breakpoint in the struct cases of the code generation and double check the instantiation is missing. If so, then try to track backwards for where it got lost.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//pull/6#issuecomment-231767498, or mute the threadhttps://github.com/notifications/unsubscribe/AE76FnPPKDYq28GnlY4rr7Ods7mG1hULks5qUl9xgaJpZM4JJZyI.

@KevinRansom
Copy link
Author

I think the generic information is there:

let mkILFieldSpec (tref:ILFieldRef,ty) =
    printfn "tref %A" (tref.EnclosingTypeRef.BasicQualifiedName)
    match tref.Type with 
    | ILType.Value tr -> 
        printfn "tr %A" (tr.BasicQualifiedName)
        tr.tspecInst |> Seq.iter(fun t ->printfn "   t: %A" (t.BasicQualifiedName))
    | _ -> ()
    { FieldRef= tref; EnclosingType=ty }

let mkILFieldSpecInTy (typ:ILType,nm,fty) = 
    match typ with 
    | ILType.Value tr -> 
        printfn "tr %A" (tr.BasicQualifiedName)
        tr.tspecInst |> Seq.iter(fun t ->printfn "   t: %A" (t.BasicQualifiedName))
    | _ -> ()
    mkILFieldSpec (mkILFieldRef (typ.TypeRef,nm,fty), typ)
c:\projects\structtuples>\KevinRansom\visualfsharp\release\net40\bin\fsc basictuple.fs /debug+ /optimize- /debug:full /r:System.ValueTuple.dll
Microsoft (R) F# Compiler version (private)
Copyright (c) Microsoft Corporation. All Rights Reserved.

basictuple.fs(4,1): warning FS0020: The result of this expression is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.
tref "<StartupCode$basictuple>.$Basictuple"
tr "System.ValueTuple`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"
   t: "System.Int32"
   t: "System.Int32"
tref "<StartupCode$basictuple>.$Basictuple"
tr "System.Int32"
tr "System.ValueTuple`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"
   t: "System.Int32"
   t: "System.Int32"
tref "System.ValueTuple`2"
tref "<StartupCode$basictuple>.$Basictuple"
tr "System.Int32"
tref "<StartupCode$basictuple>.$basictuple"
tr "System.Int32"

@dsyme dsyme merged commit e68c44e into dsyme:tuple-spike Jul 19, 2016
dsyme pushed a commit that referenced this pull request Jan 9, 2020
…otnet#8063)

* # This is a combination of 9 commits.
# This is the 1st commit message:

ref -> mutable in more places in the compiler

# The commit message #2 will be skipped:

# Update dependencies from https://github.com/dotnet/arcade build 20191229.1
#
# - Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.19629.1

# The commit message #3 will be skipped:

# Update dependencies from https://github.com/dotnet/arcade build 20191230.1
#
# - Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.19630.1

# The commit message #4 will be skipped:

# Update dependencies from https://github.com/dotnet/arcade build 20191231.1
#
# - Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.19631.1

# The commit message #5 will be skipped:

# Update dependencies from https://github.com/dotnet/arcade build 20200101.1
#
# - Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.20051.1

# The commit message #6 will be skipped:

# Update dependencies from https://github.com/dotnet/arcade build 20191216.5 (dotnet#8079)
#
# - Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19616.5

# The commit message #7 will be skipped:

# dispose fsi at the end of a scripting session (dotnet#8084)
#

# The commit message #8 will be skipped:

# Added static link tests and extended CompilerAssert (dotnet#8101)
#
# * Changed CompilerAssert to static class. Added Compile/Execute methods that take a Compilation description. Added static link tests
# 
# * Hiding compilation description internals
# 
# * Added another test to check for sanity
# 
# * Making a few optional parameters
# 
# * Hiding internals of CompilationReference

# The commit message #9 will be skipped:

# Parameterize product version (dotnet#8031)
#
# * Parameterize Product details
# 
# * fcs
# 
# * Repack pkgdef

* no ilread
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants