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

"Fatal error: Assignment of a float to a specialised non-float array" in virtual method #7426

Closed
vicuna opened this issue Dec 6, 2016 · 8 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link

commented Dec 6, 2016

Original bug ID: 7426
Reporter: tempodox
Status: closed (set by @mshinwell on 2016-12-12T10:57:23Z)
Resolution: duplicate
Priority: normal
Severity: block
Platform: Unix
OS: Mac OS X
OS Version: 10.11.6
Version: 4.04.0
Category: ~DO NOT USE (was: OCaml general)
Has duplicate: #7474
Related to: #7434 #7499
Monitored by: @gasche

Bug description

In 4.04.0+flambda, the following code produces an error from ocamlopt:

class virtual abstract = object (_ : 'self) method virtual scaleby : float -> 'self end

class concrete value =
object
inherit abstract
val _value : float = value
method value = _value
method scaleby fac =
{< _value = fac *. _value >}
end

The error message is:
Fatal error: Assignment of a float to a specialised non-float array: (array.unsafe_set[addr]<>
copy/95 _value/92
Pmulfloat/103)
Fatal error: exception Misc.Fatal_error

Steps to reproduce

Put this code in an ml file and pass it to ocamlopt:

class virtual abstract =
object (_ : 'self)
method virtual scaleby : float -> 'self
end

class concrete value =
object
inherit abstract
val _value : float = value
method value = _value
method scaleby fac =
{< _value = fac *. _value >}
end

Additional information

In 4.03+flambda, or ocamlc of 4.04+flambda, the same code compiles without error.

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 6, 2016

Comment author: @gasche

To devs: this means that we need to add more object-oriented programs to the testsuite.

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 8, 2016

Comment author: omion

I encountered the same error with a trivial program:
class some_class = object val some_val = 0.0 end

returns with the error:

Fatal error: Assignment of a float to a specialised non-float array: (array.unsafe_set[addr]<>
self/22 some_val/18
Parraysetu_arg/30)

Tested with 4.04.0 for Windows x64 and Linux armv7. As tempodox states, ocamlc, 4.04.0 without flambda, and 4.03.0 compile fine.

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 8, 2016

Comment author: @alainfrisch

I wonder if Translclass shouldn't use Psetfield to write instance variables instead of Parraysetu.

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 8, 2016

Comment author: @mshinwell

@Frisch: Indeed. Do you know why the block is treated as an array at present? (My knowledge of the object compilation model is lacking.)

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 8, 2016

Comment author: @alainfrisch

Do you know why the block is treated as an array at present?

No, I don't know.

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 10, 2016

Comment author: @garrigue

The block has to be treated as an array, because the offset is only known at runtime (due to the dynamic nature of class inheritance).
Psetfield only takes a constant offset.
My understanding was that it should be fine to assign a (boxed) float to a generic array (but of course not the way round).
Or do we need a new kind of non-specialized array for this?
Or just an indirect version of Psetfield?

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 12, 2016

Comment author: @mshinwell

I think I know what's going on here now, I will write a patch today.

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 12, 2016

Comment author: @mshinwell

Superceded by #965

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.