|
1 |
| -//public module core; |
| 1 | +public module core; |
2 | 2 |
|
3 | 3 | // Slang `core` library
|
4 | 4 |
|
@@ -603,6 +603,7 @@ void static_assert(constexpr bool condition, NativeString errorMessage);
|
603 | 603 | ///
|
604 | 604 | ///
|
605 | 605 | __magic_type(DifferentiableType)
|
| 606 | +[KnownBuiltin("IDifferentiable")] |
606 | 607 | interface IDifferentiable
|
607 | 608 | {
|
608 | 609 | // Note: the compiler implementation requires the `Differential` associated type to be defined
|
@@ -645,6 +646,7 @@ interface IDifferentiable
|
645 | 646 | /// @remarks Support for this interface is still experimental and subject to change.
|
646 | 647 | ///
|
647 | 648 | __magic_type(DifferentiablePtrType)
|
| 649 | +[KnownBuiltin("IDifferentiablePtr")] |
648 | 650 | interface IDifferentiablePtrType
|
649 | 651 | {
|
650 | 652 | __builtin_requirement($( (int)BuiltinRequirementKind::DifferentialPtrType) )
|
@@ -2367,49 +2369,6 @@ __generic<T> __extension vector<T, 4>
|
2367 | 2369 |
|
2368 | 2370 | ${{{{
|
2369 | 2371 |
|
2370 |
| -// The above extensions are generic in the *type* of the vector, |
2371 |
| -// but explicit in the *size*. We will now declare an extension |
2372 |
| -// for each builtin type that is generic in the size. |
2373 |
| -// |
2374 |
| -for (int tt = 0; tt < kBaseTypeCount; ++tt) |
2375 |
| -{ |
2376 |
| - if(kBaseTypes[tt].tag == BaseType::Void) continue; |
2377 |
| - |
2378 |
| - sb << "__generic<let N : int> __extension vector<" |
2379 |
| - << kBaseTypes[tt].name << ",N>\n{\n"; |
2380 |
| - |
2381 |
| - for (int ff = 0; ff < kBaseTypeCount; ++ff) |
2382 |
| - { |
2383 |
| - if(kBaseTypes[ff].tag == BaseType::Void) continue; |
2384 |
| - |
2385 |
| - |
2386 |
| - if( tt != ff ) |
2387 |
| - { |
2388 |
| - auto cost = getBaseTypeConversionCost( |
2389 |
| - kBaseTypes[tt], |
2390 |
| - kBaseTypes[ff]); |
2391 |
| - auto op = getBaseTypeConversionOp( |
2392 |
| - kBaseTypes[tt], |
2393 |
| - kBaseTypes[ff]); |
2394 |
| - |
2395 |
| - // Implicit conversion from a vector of the same |
2396 |
| - // size, but different element type. |
2397 |
| - sb << " __implicit_conversion(" << cost << ")\n"; |
2398 |
| - sb << " __intrinsic_op(" << int(op) << ")\n"; |
2399 |
| - sb << " __init(vector<" << kBaseTypes[ff].name << ",N> value);\n"; |
2400 |
| - |
2401 |
| - // Constructor to make a vector from a scalar of another type. |
2402 |
| - if (cost != kConversionCost_Impossible) |
2403 |
| - { |
2404 |
| - cost += kConversionCost_ScalarToVector; |
2405 |
| - sb << " __implicit_conversion(" << cost << ")\n"; |
2406 |
| - sb << " [__unsafeForceInlineEarly]\n"; |
2407 |
| - sb << " __init(" << kBaseTypes[ff].name << " value) { this = vector<" << kBaseTypes[tt].name << ",N>( " << kBaseTypes[tt].name << "(value)); }\n"; |
2408 |
| - } |
2409 |
| - } |
2410 |
| - } |
2411 |
| - sb << "}\n"; |
2412 |
| -} |
2413 | 2372 |
|
2414 | 2373 | for( int R = 1; R <= 4; ++R )
|
2415 | 2374 | for( int C = 1; C <= 4; ++C )
|
@@ -2464,38 +2423,36 @@ for( int C = 1; C <= 4; ++C )
|
2464 | 2423 | sb << "}\n";
|
2465 | 2424 | }
|
2466 | 2425 |
|
2467 |
| -for (int tt = 0; tt < kBaseTypeCount; ++tt) |
2468 |
| -{ |
2469 |
| - if(kBaseTypes[tt].tag == BaseType::Void) continue; |
2470 |
| - auto toType = kBaseTypes[tt].name; |
2471 | 2426 | }}}}
|
2472 | 2427 |
|
2473 |
| -__generic<let R : int, let C : int, let L : int> extension matrix<$(toType),R,C,L> |
| 2428 | +//@hidden: |
| 2429 | +__intrinsic_op($(kIROp_BuiltinCast)) |
| 2430 | +internal T __builtin_cast<T, U>(U u); |
| 2431 | + |
| 2432 | +// If T is implicitly convertible to U, then vector<T,N> is implicitly convertible to vector<U,N>. |
| 2433 | +__generic<ToType, let N : int> extension vector<ToType,N> |
2474 | 2434 | {
|
2475 |
| -${{{{ |
2476 |
| - for (int ff = 0; ff < kBaseTypeCount; ++ff) |
2477 |
| - { |
2478 |
| - if(kBaseTypes[ff].tag == BaseType::Void) continue; |
2479 |
| - if( tt == ff ) continue; |
| 2435 | + __implicit_conversion(constraint) |
| 2436 | + __intrinsic_op(BuiltinCast) |
| 2437 | + __init<FromType>(vector<FromType,N> value) where ToType(FromType) implicit; |
2480 | 2438 |
|
2481 |
| - auto cost = getBaseTypeConversionCost( |
2482 |
| - kBaseTypes[tt], |
2483 |
| - kBaseTypes[ff]); |
2484 |
| - auto fromType = kBaseTypes[ff].name; |
2485 |
| - auto op = getBaseTypeConversionOp( |
2486 |
| - kBaseTypes[tt], |
2487 |
| - kBaseTypes[ff]); |
2488 |
| -}}}} |
2489 |
| - __implicit_conversion($(cost)) |
2490 |
| - __intrinsic_op($(op)) |
2491 |
| - __init(matrix<$(fromType),R,C,L> value); |
2492 |
| -${{{{ |
| 2439 | + __implicit_conversion(constraint+) |
| 2440 | + [__unsafeForceInlineEarly] |
| 2441 | + [__readNone] |
| 2442 | + [TreatAsDifferentiable] |
| 2443 | + __init<FromType>(FromType value) where ToType(FromType) implicit |
| 2444 | + { |
| 2445 | + this = __builtin_cast<vector<ToType,N>>(vector<FromType,N>(value)); |
2493 | 2446 | }
|
2494 |
| -}}}} |
2495 | 2447 | }
|
2496 |
| -${{{{ |
| 2448 | + |
| 2449 | +// If T is implicitly convertible to U, then matrix<T,R,C,L> is implicitly convertible to matrix<U,R,C,L>. |
| 2450 | +__generic<ToType, let R : int, let C : int, let L : int> extension matrix<ToType,R,C,L> |
| 2451 | +{ |
| 2452 | + __implicit_conversion(constraint) |
| 2453 | + __intrinsic_op(BuiltinCast) |
| 2454 | + __init<FromType>(matrix<FromType,R,C,L> value) where ToType(FromType) implicit; |
2497 | 2455 | }
|
2498 |
| -}}}} |
2499 | 2456 |
|
2500 | 2457 | //@ hidden:
|
2501 | 2458 | __generic<T, U>
|
@@ -2643,20 +2600,20 @@ for(auto fixity : kIncDecFixities)
|
2643 | 2600 | $(fixity.qual)
|
2644 | 2601 | __generic<T : __BuiltinArithmeticType>
|
2645 | 2602 | [__unsafeForceInlineEarly]
|
2646 |
| -T operator$(op.name)(in out T value) |
2647 |
| -{$(fixity.bodyPrefix) value = value $(op.binOp) T(1); return $(fixity.returnVal); } |
| 2603 | +T operator$(op.name)( in out T value) |
| 2604 | +{ $(fixity.bodyPrefix) value = value $(op.binOp) __builtin_cast<T>(1); return $(fixity.returnVal); } |
2648 | 2605 |
|
2649 | 2606 | $(fixity.qual)
|
2650 | 2607 | __generic<T : __BuiltinArithmeticType, let N : int>
|
2651 | 2608 | [__unsafeForceInlineEarly]
|
2652 | 2609 | vector<T,N> operator$(op.name)(in out vector<T,N> value)
|
2653 |
| -{$(fixity.bodyPrefix) value = value $(op.binOp) T(1); return $(fixity.returnVal); } |
| 2610 | +{$(fixity.bodyPrefix) value = value $(op.binOp) __builtin_cast<T>(1); return $(fixity.returnVal); } |
2654 | 2611 |
|
2655 | 2612 | $(fixity.qual)
|
2656 | 2613 | __generic<T : __BuiltinArithmeticType, let R : int, let C : int, let L : int>
|
2657 | 2614 | [__unsafeForceInlineEarly]
|
2658 | 2615 | matrix<T,R,C> operator$(op.name)(in out matrix<T,R,C,L> value)
|
2659 |
| -{$(fixity.bodyPrefix) value = value $(op.binOp) T(1); return $(fixity.returnVal); } |
| 2616 | +{$(fixity.bodyPrefix) value = value $(op.binOp) __builtin_cast<T>(1); return $(fixity.returnVal); } |
2660 | 2617 |
|
2661 | 2618 | $(fixity.qual)
|
2662 | 2619 | __generic<T, let addrSpace : uint64_t>
|
|
0 commit comments