Bug 38220 - fsharpi crashes for some combinations of instantiating an object by an interface
Summary: fsharpi crashes for some combinations of instantiating an object by an interface
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 4.0.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-30 14:14 UTC by Jon Sporring
Modified: 2017-09-06 15:00 UTC (History)
5 users (show)

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

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

Description Jon Sporring 2016-01-30 14:14:14 UTC
I'm uncertain, whether this is the right classification of this bug, but I could not find subject specifically related to sharp nor fsharpi. 

In the following, I instantiate an interface and an object using this interface. fsharpi crashes, if I have the use ';;' between the the definition of the interface and the instantiation, but not if it is all in the same scope (no ';;') in between.

> mono --version
Mono JIT compiler version 4.2.1 (explicit/6dd2d0d Fri Nov  6 12:25:19 EST 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          yes(3.6.0svn-mono-(detached/a173357)
	GC:            seen
> fsharpi
F# Interactive for F# 4.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License

For help type #help;;

> type INumeric<'T> =
-     abstract Zero : 'T
-     abstract Subtract : 'T * 'T -> 'T
-     abstract LessThan : 'T * 'T -> bool
- ;;

type INumeric<'T> =
  interface
    abstract member LessThan : 'T * 'T -> bool
    abstract member Subtract : 'T * 'T -> 'T
    abstract member Zero : 'T
  end

> let intOps =
-     {new INumeric<int> with
-         member ops.Zero = 0
-         member ops.Subtract (x, y) = x - y
-         member ops.LessThan (x, y) = x < y}
- ;;
* Assertion at metadata.c:1016, condition `idx < t->rows' not met

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Runtime.Remoting.Activation.ActivationServices.AllocateUninitializedClassInstance (System.Type) <0xffffffff>
  at System.Runtime.Serialization.FormatterServices.nativeGetUninitializedObject (System.RuntimeType) <0x0001d>
  at System.Runtime.Serialization.FormatterServices.GetUninitializedObject (System.Type) <0x00073>
  at Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter.envUpdateCreatedTypeRef (Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter/emEnv,Microsoft.FSharp.Compiler.AbstractIL.IL/ILTypeRef) <0x0012f>
  at Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter/emEnv@1936-9.Invoke (Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter/emEnv,Microsoft.FSharp.Compiler.AbstractIL.IL/ILTypeRef) <0x00017>
  at Microsoft.FSharp.Collections.SeqModule.Fold<T_REF, TResult_REF> (Microsoft.FSharp.Core.FSharpFunc`2<TResult_REF, Microsoft.FSharp.Core.FSharpFunc`2<T_REF, TResult_REF>>,TResult_REF,System.Collections.Generic.IEnumerable`1<T_REF>) <0x000d8>
  at Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter.buildModuleFragment (Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter/cenv,Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter/emEnv,System.Reflection.Emit.AssemblyBuilder,System.Reflection.Emit.ModuleBuilder,Microsoft.FSharp.Compiler.AbstractIL.IL/ILModuleDef) <0x004f3>
  at Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter.emitModuleFragment (Microsoft.FSharp.Compiler.AbstractIL.IL/ILGlobals,Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter/emEnv,System.Reflection.Emit.AssemblyBuilder,System.Reflection.Emit.ModuleBuilder,Microsoft.FSharp.Compiler.AbstractIL.IL/ILModuleDef,bool,Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Compiler.AbstractIL.IL/ILAssemblyRef, Microsoft.FSharp.Core.FSharpOption`1<Microsoft.FSharp.Core.FSharpChoice`2<string, System.Reflection.Assembly>>>) <0x0006b>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompiler.ProcessInputs (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.Ast/ParsedInput>,bool,bool,bool,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.Ast/Ident>) <0x0044f>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompiler.EvalParsedDefinitions (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,bool,bool,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.Ast/SynModuleDecl>) <0x001d7>
  at Microsoft.FSharp.Compiler.Interactive.Shell/clo@1606-45.Invoke (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x01497>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.InteractiveCatch<T_REF> (Microsoft.FSharp.Core.FSharpFunc`2<T_REF, System.Tuple`2<T_REF, Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionStepStatus>>,T_REF) <0x00039>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.ExecInteraction (bool,Microsoft.FSharp.Compiler.CompileOps/TcConfig,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Compiler.Ast/ParsedFsiInteraction) <0x00067>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.ExecInteractions (bool,Microsoft.FSharp.Compiler.CompileOps/TcConfig,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Core.FSharpOption`1<Microsoft.FSharp.Compiler.Ast/ParsedFsiInteraction>) <0x0098f>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.MainThreadProcessParsedInteraction (bool,Microsoft.FSharp.Core.FSharpOption`1<Microsoft.FSharp.Compiler.Ast/ParsedFsiInteraction>,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x0012f>
  at Microsoft.FSharp.Compiler.Interactive.Shell/res@1819.Invoke (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x00033>
  at Microsoft.FSharp.Compiler.Interactive.Shell/runCodeOnMainThread@2058-2<T_REF>.Invoke (Microsoft.FSharp.Core.Unit) <0x0003b>
  at <StartupCode$FSharp-Compiler-Interactive-Settings>.$Fsiaux/Microsoft-FSharp-Compiler-Interactive-IEventLoop-Invoke@47<T_REF>.Invoke (Microsoft.FSharp.Core.Unit) <0x0001a>
  at <StartupCode$FSharp-Compiler-Interactive-Settings>.$Fsiaux/run@38-4.Invoke (Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit, object>) <0x00039>
  at Microsoft.FSharp.Primitives.Basics.List.iter<T_REF> (Microsoft.FSharp.Core.FSharpFunc`2<T_REF, Microsoft.FSharp.Core.Unit>,Microsoft.FSharp.Collections.FSharpList`1<T_REF>) <0x00038>
  at Microsoft.FSharp.Collections.ListModule.Iterate<T_REF> (Microsoft.FSharp.Core.FSharpFunc`2<T_REF, Microsoft.FSharp.Core.Unit>,Microsoft.FSharp.Collections.FSharpList`1<T_REF>) <0x00027>
  at <StartupCode$FSharp-Compiler-Interactive-Settings>.$Fsiaux.run@35 (Microsoft.FSharp.Compiler.Interactive.SimpleEventLoop,Microsoft.FSharp.Core.Unit) <0x000cb>
  at Microsoft.FSharp.Compiler.Interactive.SimpleEventLoop.Microsoft-FSharp-Compiler-Interactive-IEventLoop-Run () <0x0001f>
  at Microsoft.FSharp.Compiler.Interactive.Shell.runLoop@2103 (Microsoft.FSharp.Compiler.Interactive.Shell/FsiConsoleOutput,Microsoft.FSharp.Core.Unit) <0x00205>
  at Microsoft.FSharp.Compiler.Interactive.Shell.DriveFsiEventLoop (Microsoft.FSharp.Compiler.Interactive.Shell/FsiConsoleOutput) <0x0001b>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiEvaluationSession.Run () <0x00bcb>
  at Microsoft.FSharp.Compiler.Interactive.Shell.evaluateSession@2420 (string[],Microsoft.FSharp.Core.Unit) <0x0009b>
  at Microsoft.FSharp.Compiler.Interactive.Shell.MainMain (string[]) <0x00127>
  at Microsoft.FSharp.Compiler.Interactive.Main.FsiMain (string[]) <0x00013>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

	0   mono                                0x000ec186 mono_handle_native_sigsegv + 342
	1   mono                                0x0013c891 sigabrt_signal_handler + 129
	2   libsystem_platform.dylib            0x9e6f201b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   libsystem_c.dylib                   0x9a6c2c34 abort + 156
	5   mono                                0x00290d11 monoeg_log_default_handler + 129
	6   mono                                0x00290e0b monoeg_assertion_message + 107
	7   mono                                0x001a2150 mono_metadata_decode_row + 224
	8   mono                                0x001a25aa mono_metadata_decode_table_row + 90
	9   mono                                0x0015112e find_method_in_metadata + 110
	10  mono                                0x0014a713 mono_class_init + 1155
	11  mono                                0x0014b4fd collect_implemented_interfaces_aux + 109
	12  mono                                0x0014dc74 mono_class_setup_vtable_general + 436
	13  mono                                0x0014da33 mono_class_setup_vtable_full + 291
	14  mono                                0x0014b360 mono_class_setup_vtable + 16
	15  mono                                0x00201ef4 mono_class_vtable_full + 356
	16  mono                                0x00174da1 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance + 161
	17  ???                                 0x053c7cc4 0x0 + 87850180
	18  mscorlib.dll.dylib                  0x018b1b8e System_Runtime_Serialization_FormatterServices_nativeGetUninitializedObject_System_RuntimeType + 30
	19  mscorlib.dll.dylib                  0x018b1854 System_Runtime_Serialization_FormatterServices_GetUninitializedObject_System_Type + 116
	20  ???                                 0x0512ac28 0x0 + 85109800
	21  ???                                 0x0512aae8 0x0 + 85109480
	22  ???                                 0x0498f431 0x0 + 77132849
	23  ???                                 0x051133fc 0x0 + 85013500
	24  ???                                 0x05112d0c 0x0 + 85011724
	25  ???                                 0x049a2498 0x0 + 77210776
	26  ???                                 0x0499ffe0 0x0 + 77201376
	27  ???                                 0x052522a8 0x0 + 86319784
	28  ???                                 0x0499fc1a 0x0 + 77200410
	29  ???                                 0x05250d68 0x0 + 86314344
	30  ???                                 0x0524fbb0 0x0 + 86309808
	31  ???                                 0x0524ee60 0x0 + 86306400
	32  ???                                 0x0524ed1c 0x0 + 86306076
	33  ???                                 0x0524ece4 0x0 + 86306020
	34  ???                                 0x0524eca3 0x0 + 86305955
	35  ???                                 0x0524eba2 0x0 + 86305698
	36  ???                                 0x03a2eac9 0x0 + 61008585
	37  ???                                 0x03a2ea80 0x0 + 61008512
	38  ???                                 0x0511e814 0x0 + 85059604
	39  ???                                 0x0511e730 0x0 + 85059376
	40  ???                                 0x0511e31e 0x0 + 85058334
	41  ???                                 0x0511e104 0x0 + 85057796
	42  ???                                 0x0499f7d4 0x0 + 77199316
	43  ???                                 0x0070d6cc 0x0 + 7395020
	44  ???                                 0x0070d130 0x0 + 7393584
	45  ???                                 0x0070cedc 0x0 + 7392988
	46  ???                                 0x0070cfb4 0x0 + 7393204
	47  mono                                0x0003cd5a mono_jit_runtime_invoke + 714
	48  mono                                0x0020152f mono_runtime_invoke + 127
	49  mono                                0x00207281 mono_runtime_exec_main + 401
	50  mono                                0x0020703a mono_runtime_run_main + 618
	51  mono                                0x000b504d mono_jit_exec + 93
	52  mono                                0x000b7360 mono_main + 7920
	53  mono                                0x0002f650 main + 768
	54  mono                                0x0002f345 start + 53

Debug info from gdb:

(lldb) command source -s 0 '/tmp/mono-gdb-commands.RPsn6q'
Executing commands in '/tmp/mono-gdb-commands.RPsn6q'.
(lldb) process attach --pid 24720
error: attach failed: unable to attach

=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Abort trap: 6
Comment 1 Jon Purdy 2016-02-09 19:23:33 UTC
I started investigating this. It looks related to a workaround in F# for older Mono versions[1]. I hope that a fix doesn’t require patching F#. Will update as I know more.

[1]: https://github.com/fsharp/fsharp/blob/3b4fee35ad5d40ea9066e6236553bbd052f0232e/src/absil/ilreflect.fs#L392
Comment 2 Jon Purdy 2016-02-10 21:05:00 UTC
This was addressed in #35375[1]. I have opened a pull request[2] to backport these changes to 4.2. If possible, you can also upgrade your Mono version to 4.3.1 or later.

[1]: https://bugzilla.xamarin.com/show_bug.cgi?id=35375

[2]: https://github.com/mono/mono/pull/2596
Comment 3 Ludovic Henry 2017-09-06 15:00:52 UTC
I can't reproduce with Mono 5.4.0.60 (2017-06/733b515), marking as fixed. If you can still reproduce, please feel free to reopen. Thank you.