Ayrat
Vladislav
where a : class
Ayrat
Vladislav
че бага что ль или я туплю
Ayrat
а боксинг на классах вообще что-то делает?
Vasily
Ща, разберусь с яндексом, и сразу к вам присоединюсь :)
Vladislav
мне кажется ничего
Ayrat
я знаешь не подозревал что я могу кроссреференсить параметры в параметрах
Ayrat
и они друг друга отрезолвливают
Vladislav
What it's saying is that the compiler can assume that it's safe to box a reference type. So with generics, the compiler has two choices: emit the code that is guaranteed to work regardless of how the generic type is constrained, or optimize the code and omit redundant instructions where it can prove them to be unnecessary.
The Microsoft C# compiler, in general, tends to choose the simpler approach and leave all optimization to the JIT stage. To me, it looks like your example is exactly that: not optimizing something because implementing an optimization takes time, and saving this box instruction probably has very little value in practice.
C# allows even an unconstrained generic-typed value to be compared to null, so the compiler must support this general case. The easiest way to implement this general case is to use the box instruction, which does all the heavy-lifting of handling reference, value and nullable types, correctly pushing either a reference or a null value onto the stack. So the easiest thing for the compiler to do is to issue box regardless of the constraints, and then compare the value to zero (brtrue).
Vladislav
это про сишорп
Анна
@angmarr промокод на f(by) выложили!
https://www.facebook.com/groups/funcby/permalink/2166154090115621/
Vladislav
но бля тут констрейнт на класс
Ayrat
если тебя констрейн смущает
Ayrat
и ты хочешь генерик
Vladislav
не, я хочу чтобы боксинга не было т.к. известно что там референс тип)
Ayrat
но сравнение null и структур бессмысленно
Ayrat
Ayrat
The box instruction can be applied to more than just value types; such types are called boxable
types. A type is boxable if it is one of the following
...
A reference type (including classes, arrays, delegates, and instantiations of generic classes)
excluding managed pointers/byrefs (§I.8.2.1.1)
A generic parameter (to a generic type definition, or a generic method definition) [Note:
Boxing and unboxing of generic arguments adds performance overhead to a CLI
implementation. The constrained. prefix can improve performance during virtual dispatch
to a method defined by a value type, by avoiding boxing the value type. end note]
The type System.Void is never boxable.
Vladislav
Ayrat
If typeTok is a reference type, the box instruction does returns val unchanged as obj.
Vladislav
а сек
Ayrat
короче, операция box на реф типах нихуя не делает кроме апкаста в object
Ayrat
так что похуй
Andrew
Andrew
Это видимо сделано чтобы не надо было проверку ебашить на тип
Andrew
Просто боксишь что угодно и все
Vladislav
Vladislav
[CompilationArgumentCounts(new int[] {1, 1})]
[SpecialName]
public static a \u007CDefaultArg\u007C<a>(a def, a obj) where a : class
{
if ((object) obj == null)
return def;
return obj;
}
[CompilationArgumentCounts(new int[] {1, 1})]
[SpecialName]
public static a \u007CDefaultArg1\u007C<a>(a def, a obj)
{
if (object.ReferenceEquals((object) obj, (object) null))
return def;
return obj;
}
Vladislav
в первом варианте он не нужен
Vladislav
во 2 да
Ayrat
ну каст то лишний
я не уверен что там что-то делается.
JIT может нахуй касты в object посылать
Ayrat
типа камон, это самый общий тип, виртуалная таблица его методов должна быть закеширована тыщу раз
Vladislav
Ayrat
Vladislav
VS command prompt
Vladislav
спс
Vladislav
Ayrat
это да, полезно
Pavel
Ayrat
причём с вложенностью
Pavel
это примерно в такое наверно внутрях раскладывается let defaultArgNull' obj x def =
let (IfNull def obj) = obj
let (IfNull obj x) = x
printfn "obj: %A; x: %A; def: %A" obj x def
Pavel
в таком виде взрыва нет. хотя тоже самое )
Vladislav
каст в релизе тоже есть
Ayrat
Vladislav
короче без box все работает))
Ayrat
но с box тоже!
Vladislav
касты !11 перфоманс!11
Vladislav
https://github.com/Microsoft/visualfsharp/issues/6042
Vladislav
посмотрим
Анна
Прикольно, сейчас одновременно в двух чатах обсуждают первый язык программирования
Vladislav
Анна
а не первый в мире
Vladislav
У меня С по-сути
Vladislav
Сразу в ад
Анна
Тема "на каком языке начинать изучать прогу" всплывает периодически, так как горячая. Просто прикольно, что одновременно в разных местах всплыла
Dmitry
Хорошо, когда в школе не было программирования и можно не читать тред про первый язык программирования
Vladislav
У меня Паскаль был
Vladislav
Но к моменту универа я не помнил его
Igor
Vagif
Чем больше отхожу от ООП, тем больше согласен с Линусом, что на Си лучше писать, чем на Си++
Vladislav
Я спустя 3 месяца только разбираться в чём-то начал, вроде
Hog
Польская и в МК54 была
Hog
Мк у меня не было
Roman
А в плюсах есть?
Roman
А вывод типов тут при чем?
Roman
Няня я у них поел
Romɑn
Roman
Мб реплики составлены цепями Маркова)
Romɑn
Roman
Контекст системы типов