Bug 19176 - invalid code generation for async+linq code
Summary: invalid code generation for async+linq code
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-04-18 20:42 UTC by Jon Goldberger [MSFT]
Modified: 2014-05-02 09:33 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project (258.96 KB, application/zip)
2014-04-18 20:42 UTC, Jon Goldberger [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Comment 2 Jon Goldberger [MSFT] 2014-04-18 20:44:53 UTC
From case:

I've started iOS development for our app, but the shared project AOT fails
when targeting an actual device (works in simulator) with
generic_sharing_context
assertion<https://github.com/mono/mono/blob/master/mono/mini/method-to-ir.c#L717>(see
complete error below).

This is happening with both stable and alpha channels.

Is there any way to easily attach a debugger (on mac) to the mono runtime
and catch the assertion such that I'd know what C# type is causing it and
possibly fix it? Currently it would be like looking for a needle in a
haystack, commenting out code to finally arrive at the reason why it's not
working.

Build log:

*Compiling to native code*
> /Developer/MonoTouch/usr/bin/mtouch -sdkroot
> "/Applications/Xcode.app/Contents/Developer" --cache
> "/Users/mart/Projects/Toggl/mobile_dot/Ross/obj/iPhone/Debug/mtouch-cache"
> --nomanifest --nosign -dev
> "/Users/mart/Projects/Toggl/mobile_dot/Ross/bin/iPhone/Debug/Ross.app" -r
> "/Users/mart/Projects/Toggl/mobile_dot/Phoebe/bin/iOS/Debug/Phoebe.dll" -r
> "/Users/mart/Projects/Toggl/mobile_dot/Contrib/Cirrious.FluentLayout/Cirrious.FluentLayout/bin/iPhoneSimulator/Debug/Cirrious.FluentLayouts.Touch.dll"
> -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" -r
> "/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" -r
> "/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" -r
> "/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" -debug -linksdkonly
> -sdk "7.1" -targetver "7.0" --abi=armv7
> "/Users/mart/Projects/Toggl/mobile_dot/Ross/bin/iPhone/Debug/Ross.exe"
> Xamarin.iOS 7.2.1 Business Edition using framework:
> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk
> AOT Compilation exited with code 134, command:
> MONO_PATH=/Users/mart/Projects/Toggl/mobile_dot/Ross/obj/iPhone/Debug/mtouch-cache/Build
> /Developer/MonoTouch/usr/bin/arm-darwin-mono-boehm --debug -O=gsharedvt
> --aot=mtriple=armv7-ios,full,static,asmonly,direct-icalls,soft-debug,dwarfdebug,no-direct-calls,iphone-abi,outfile=/Users/mart/Projects/Toggl/mobile_dot/Ross/obj/iPhone/Debug/mtouch-cache/Phoebe.dll.armv7.s
> "/Users/mart/Projects/Toggl/mobile_dot/Ross/obj/iPhone/Debug/mtouch-cache/Build/Phoebe.dll"
> Mono Ahead of Time compiler - compiling assembly
> /Users/mart/Projects/Toggl/mobile_dot/Ross/obj/iPhone/Debug/mtouch-cache/Build/Phoebe.dll
> * Assertion at ../../../../../mono/mono/mini/method-to-ir.c:717, condition
> `cfg->generic_sharing_context' not met
>
> error MT3001: Could not AOT the assembly
> '/Users/mart/Projects/Toggl/mobile_dot/Ross/obj/iPhone/Debug/mtouch-cache/Build/Phoebe.dll'


I composed a test-case with the DLLs and build.sh to execute the above
command. [Attached to bug report]

The source for the project is up on Github:
https://github.com/toggl/mobile/tree/bb04c7313d788352a12ec9f345662754ef92ed05

-----------------------------------------------------------------

 I narrowed down the problem to 3 lines:
TogglRestClient.cs:148<https://github.com/toggl/mobile/blob/bb04c7313d788352a12ec9f345662754ef92ed05/Phoebe/Net/TogglRestClient.cs#L148>;
, TogglRestClient.cs:154<https://github.com/toggl/mobile/blob/bb04c7313d788352a12ec9f345662754ef92ed05/Phoebe/Net/TogglRestClient.cs#L154>;
and
TogglRestClient.cs:156<https://github.com/toggl/mobile/blob/bb04c7313d788352a12ec9f345662754ef92ed05/Phoebe/Net/TogglRestClient.cs#L156>;.
What fails there is the lambda function passed into select. Apparently the
AOT wasn't able to compile the generic function calls. Though, it is able
to compile (
object model) => DeleteClient ((ClientModel)model) successfully.
Comment 3 Zoltan Varga 2014-04-19 02:24:46 UTC
Phoebe.dll contains the following method:

    .method private hidebysig 
           instance default class [mscorlib]System.Threading.Tasks.Task '<Delete`1>m__3' (!!0 model)  cil managed 

This method is not generic, but it has a generic parameter as a parameter, which is not valid IL. What c# compiler and what version created this file ?
Comment 4 Mart Roosmaa 2014-04-19 03:02:17 UTC
The issue was present for both stable and alpha channels.

Xamarin Studio: 4.3.4 (build 0)
Xamarin.iOS: 7.2.1.34 (Business Edition)
Mono 3.4.0 ((no/d4511ef)

Built with Xamarin Studios, so the default compiler for used for iOS projects.
Comment 5 Zoltan Varga 2014-05-01 14:38:34 UTC
This is an mcs problem. Testcase:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;

public class Model {
}

public class Tests {

	Task DeleteClient (Model m) {
		return null;
	}

	public async Task Delete<T> (IEnumerable<T> models)
		where T : Model
	{
		await Task.WhenAll (models.Select ((model) => DeleteClient (model)));
	}

	public static void Main (String[] args) {
	}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

The '<Delete`1>m__0' method generated by mcs has the following IL signature:

   .method private hidebysig 
          instance default class [mscorlib]System.Threading.Tasks.Task '<Delete`1>m__0' (!!0 model)  cil managed

The parameter has a mvar type, but the method is not generic.

This happens with mcs with master.
Comment 6 Marek Safar 2014-05-02 09:33:12 UTC
Fixed in master