diff
stringlengths
41
2.03M
msg
stringlengths
1
1.5k
repo
stringlengths
5
40
sha
stringlengths
40
40
time
stringlengths
20
20
mmm a / hphp / hack / src / server / serverExtractStandalone . ml <nl> ppp b / hphp / hack / src / server / serverExtractStandalone . ml <nl> let get_dependency_origin cls ( dep : Typing_deps . Dep . variant ) = <nl> | Cstr cls - > cls <nl> | _ - > raise UnexpectedDependency ) ) <nl> <nl> - let collect_dependencies tcopt target = <nl> + let get_dependencies tcopt target = <nl> let dependencies = HashSet . create 0 in <nl> - Typing_deps . Dep . ( <nl> - let add_dependency root obj = <nl> - if is_relevant_dependency target root then do_add_dep dependencies obj <nl> - in <nl> - Typing_deps . add_dependency_callback " add_dependency " add_dependency ; <nl> - let filename = get_filename target in <nl> - ( * Collect dependencies through side effects of typechecking and remove the extracted <nl> - function / method from the set of dependencies to avoid declaring it twice . * ) <nl> - let ( ) = <nl> + let add_dependency root obj = <nl> + if is_relevant_dependency target root then do_add_dep dependencies obj <nl> + in <nl> + Typing_deps . add_dependency_callback " add_dependency " add_dependency ; <nl> + let filename = get_filename target in <nl> + ( * Collect dependencies through side effects of typechecking and remove <nl> + * the target function / method from the set of dependencies to avoid <nl> + * declaring it twice . <nl> + * ) <nl> + let ( ) = <nl> + Typing_deps . Dep . ( <nl> match target with <nl> | Function func - > <nl> let ( _ : ( Tast . def * Typing_env_types . global_tvenv ) option ) = <nl> let collect_dependencies tcopt target = <nl> Typing_check_service . type_class tcopt filename cls <nl> in <nl> HashSet . remove dependencies ( Method ( cls , m ) ) ; <nl> - HashSet . remove dependencies ( SMethod ( cls , m ) ) <nl> - in <nl> - let types = Caml . Hashtbl . create 0 in <nl> - let globals = HashSet . create 0 in <nl> - let group_by_type obj = <nl> - if is_class_dependency obj then ( <nl> + HashSet . remove dependencies ( SMethod ( cls , m ) ) ) <nl> + in <nl> + dependencies <nl> + <nl> + let split_dependencies dependencies = <nl> + let types = Caml . Hashtbl . create 0 in <nl> + let globals = HashSet . create 0 in <nl> + let group_by_type obj = <nl> + if is_class_dependency obj then ( <nl> + Typing_deps . Dep . ( <nl> match obj with <nl> | Class cls - > <nl> ( match Caml . Hashtbl . find_opt types cls with <nl> let collect_dependencies tcopt target = <nl> | None - > <nl> let set = HashSet . create 0 in <nl> Caml . Hashtbl . add types cls set ) <nl> - ( * We already added the members when adding signature dependencies , omit it from generation * ) <nl> + ( * We already added the members when adding signature dependencies , <nl> + * omit it from generation <nl> + * ) <nl> | AllMembers _ - > ( ) <nl> | Extends _ - > ( ) <nl> | _ - > <nl> let cls = get_class_name obj in <nl> let origin = get_dependency_origin cls obj in <nl> ( * Consider the following example : <nl> - * class Base { <nl> - * public static function do ( ) : void { } <nl> - * } <nl> - * class Derived extends Base { } <nl> - * function f ( ) : void { <nl> - * Derived : : do ( ) ; <nl> - * } <nl> - * We will pull both SMethod ( Base , do ) and SMethod ( Derived , do ) as dependencies , but we should <nl> - * not generate method do ( ) in Derived . Therefore we should ignore dependencies whose origin <nl> - * differ from their class . * ) <nl> + * <nl> + * class Base { <nl> + * public static function do ( ) : void { } <nl> + * } <nl> + * class Derived extends Base { } <nl> + * function f ( ) : void { <nl> + * Derived : : do ( ) ; <nl> + * } <nl> + * <nl> + * We will pull both SMethod ( Base , do ) and SMethod ( Derived , do ) as <nl> + * dependencies , but we should not generate method do ( ) in Derived . <nl> + * Therefore we should ignore dependencies whose origin differ from <nl> + * their class . <nl> + * ) <nl> if origin = cls then ( <nl> match Caml . Hashtbl . find_opt types cls with <nl> | Some set - > HashSet . add set obj <nl> let collect_dependencies tcopt target = <nl> let set = HashSet . create 0 in <nl> HashSet . add set obj ; <nl> Caml . Hashtbl . add types cls set <nl> - ) <nl> - ) else <nl> - HashSet . add globals obj <nl> - in <nl> - HashSet . iter group_by_type dependencies ; <nl> - ( types , globals ) ) <nl> + ) ) <nl> + ) else <nl> + HashSet . add globals obj <nl> + in <nl> + HashSet . iter group_by_type dependencies ; <nl> + ( types , globals ) <nl> <nl> ( * Every namespace can contain declarations of classes , functions , constants <nl> as well as nested namespaces * ) <nl> let get_declarations tcopt target types globals = <nl> <nl> let go tcopt target = <nl> try <nl> - let ( types , globals ) = collect_dependencies tcopt target in <nl> + let ( types , globals ) = <nl> + split_dependencies ( get_dependencies tcopt target ) <nl> + in <nl> let declarations = get_declarations tcopt target types globals in <nl> get_code declarations <nl> with <nl>
Split up collect_dependency into collection of dependencies followed by classification into class and other dependencies
facebook/hhvm
7b8d0ca281b8a1611ccf1157e69a4dc2c1afbb64
2019-10-01T09:46:37Z
mmm a / src / objects / elements . cc <nl> ppp b / src / objects / elements . cc <nl> class ElementsAccessorBase : public InternalElementsAccessor { <nl> IsAnyNonextensibleElementsKind ( kind ( ) ) ) ; <nl> size_t length = Subclass : : GetMaxIndex ( holder , backing_store ) ; <nl> if ( IsHoleyElementsKindForRead ( kind ( ) ) ) { <nl> - DCHECK_IMPLIES ( index < length , index < = std : : numeric_limits < int > : : max ( ) ) ; <nl> + DCHECK_IMPLIES ( <nl> + index < length , <nl> + index < = static_cast < size_t > ( std : : numeric_limits < int > : : max ( ) ) ) ; <nl> return index < length & & <nl> ! BackingStore : : cast ( backing_store ) <nl> . is_the_hole ( isolate , static_cast < int > ( index ) ) <nl>
Fix sign / unsigned mismatch in ElementsAccessorBase .
v8/v8
95db6d6b2cdf84fc6b1ed4edcfb3eaf1ab2873a9
2019-12-11T11:53:52Z
mmm a / jstests / concurrency / fsm_workloads / multi_statement_transaction_simple . js <nl> ppp b / jstests / concurrency / fsm_workloads / multi_statement_transaction_simple . js <nl> <nl> * / <nl> var $ config = ( function ( ) { <nl> <nl> + / / For isWiredTiger . <nl> + load ( " jstests / concurrency / fsm_workload_helpers / server_types . js " ) ; <nl> + <nl> function _calcTotalMoneyBalances ( sessionDb , txnNumber , collName ) { <nl> let res = sessionDb . runCommand ( { <nl> find : collName , <nl> var $ config = ( function ( ) { <nl> } ; <nl> <nl> var skip = function skip ( cluster ) { <nl> - if ( cluster . isSharded ( ) | | cluster . isStandalone ( ) ) { <nl> - return { skip : true , msg : ' only runs in a replica set . ' } ; <nl> + if ( cluster . isSharded ( ) | | cluster . isStandalone ( ) | | <nl> + ! isWiredTiger ( cluster . getDB ( " admin " ) ) ) { <nl> + return { skip : true , msg : ' only runs in a replica set with WiredTiger . ' } ; <nl> } <nl> return { skip : false } ; <nl> } ; <nl>
SERVER - 33974 multi - statement transaction FSM test should only be run in WiredTiger engine
mongodb/mongo
17eebc8ac8bfcff0b8d2b8b2a1d97187efd6efca
2018-03-19T16:22:39Z
mmm a / contrib / CMakeLists . txt <nl> ppp b / contrib / CMakeLists . txt <nl> endif ( ) <nl> <nl> if ( USE_INTERNAL_BROTLI_LIBRARY ) <nl> add_subdirectory ( brotli - cmake ) <nl> + target_compile_definitions ( brotli PRIVATE BROTLI_BUILD_PORTABLE = 1 ) <nl> endif ( ) <nl> <nl> if ( USE_INTERNAL_PROTOBUF_LIBRARY ) <nl>
HTTP Accept - Encoding : br ; Build brotli without UB
ClickHouse/ClickHouse
a642848c651d574a3bf597f51b8b2b7ea057af0b
2019-03-21T09:02:42Z
mmm a / update_version . py <nl> ppp b / update_version . py <nl> def CreateNode ( tagname , indent , children ) : <nl> FindAndClone ( root , ' date ' ) , <nl> FindAndClone ( root , ' time ' ) , <nl> FindAndClone ( root , ' license ' ) , <nl> - FindAndClone ( root , ' notes ' ) <nl> + CreateNode ( ' notes ' , 3 , [ ] ) , <nl> ] ) <nl> changelog . appendChild ( release ) <nl> changelog . appendChild ( document . createTextNode ( ' \ n ' ) ) <nl>
Tweaked update_version . py to leave PHP notes blank
protocolbuffers/protobuf
1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26
2020-08-21T23:33:52Z
mmm a / xbmc / storage / MediaManager . cpp <nl> ppp b / xbmc / storage / MediaManager . cpp <nl> std : : vector < std : : string > CMediaManager : : GetDiskUsage ( ) <nl> return m_platformStorage - > GetDiskUsage ( ) ; <nl> } <nl> <nl> + namespace <nl> + { <nl> + void ShowGUINotification ( CGUIDialogKaiToast : : eMessageType eType , const std : : string & caption , const std : : string & message ) <nl> + { <nl> + int activeWindow = CServiceBroker : : GetGUI ( ) - > GetWindowManager ( ) . GetActiveWindow ( ) ; <nl> + if ( activeWindow ! = WINDOW_FULLSCREEN_VIDEO & & <nl> + activeWindow ! = WINDOW_FULLSCREEN_GAME & & <nl> + activeWindow ! = WINDOW_VISUALISATION & & <nl> + activeWindow ! = WINDOW_SLIDESHOW ) <nl> + { <nl> + CGUIDialogKaiToast : : QueueNotification ( eType , caption , message , TOAST_DISPLAY_TIME , false ) ; <nl> + } <nl> + } <nl> + } / / unnamed namespace <nl> + <nl> void CMediaManager : : OnStorageAdded ( const std : : string & label , const std : : string & path ) <nl> { <nl> # ifdef HAS_DVD_DRIVE <nl> void CMediaManager : : OnStorageAdded ( const std : : string & label , const std : : string & <nl> else <nl> CJobManager : : GetInstance ( ) . AddJob ( new CAutorunMediaJob ( label , path ) , this , CJob : : PRIORITY_HIGH ) ; <nl> else <nl> - CGUIDialogKaiToast : : QueueNotification ( CGUIDialogKaiToast : : Info , g_localizeStrings . Get ( 13021 ) , label , TOAST_DISPLAY_TIME , false ) ; <nl> + ShowGUINotification ( CGUIDialogKaiToast : : Info , g_localizeStrings . Get ( 13021 ) , label ) ; <nl> # endif <nl> } <nl> <nl> void CMediaManager : : OnStorageSafelyRemoved ( const std : : string & label ) <nl> { <nl> - CGUIDialogKaiToast : : QueueNotification ( CGUIDialogKaiToast : : Info , g_localizeStrings . Get ( 13023 ) , label , TOAST_DISPLAY_TIME , false ) ; <nl> + ShowGUINotification ( CGUIDialogKaiToast : : Info , g_localizeStrings . Get ( 13023 ) , label ) ; <nl> } <nl> <nl> void CMediaManager : : OnStorageUnsafelyRemoved ( const std : : string & label ) <nl> { <nl> - CGUIDialogKaiToast : : QueueNotification ( CGUIDialogKaiToast : : Warning , g_localizeStrings . Get ( 13022 ) , label ) ; <nl> + ShowGUINotification ( CGUIDialogKaiToast : : Warning , g_localizeStrings . Get ( 13022 ) , label ) ; <nl> } <nl> <nl> CMediaManager : : DiscInfo CMediaManager : : GetDiscInfo ( const std : : string & mediaPath ) <nl>
[ storage ] MediaManager : : Onstorage * : Do not show toasts if fullscreen window is active . User is not interesred in mount notifications while watching videos etc .
xbmc/xbmc
e58628584ea8424a63c5d3c969cfe400aed46912
2018-11-15T16:16:13Z
mmm a / test / lit . cfg <nl> ppp b / test / lit . cfg <nl> elif run_os in [ ' linux - gnu ' , ' linux - gnueabihf ' , ' freebsd ' , ' windows - cygnus ' , ' wi <nl> ( config . variant_triple , clang_mcp_opt ) ) <nl> config . target_ld = " ld - L % r " % ( make_path ( test_resource_dir , config . target_sdk_name ) ) <nl> elif run_os = = ' linux - androideabi ' or run_os = = ' linux - android ' : <nl> + # The module triple for Android ARMv7 seems to be canonicalized in LLVM <nl> + # to be armv7 - none - linux - android , without the " eabi " bit . Let ' s remove the <nl> + # same bit from the substitutions so the tests pass correctly . <nl> + target_specific_module_triple = re . sub ( r ' androideabi ' , ' android ' , <nl> + target_specific_module_triple ) <nl> + config . variant_triple = re . sub ( r ' androideabi ' , ' android ' , config . variant_triple ) <nl> def get_architecture_value ( * * kwargs ) : <nl> result = kwargs [ run_cpu ] <nl> if result is None : <nl>
Merge remote - tracking branch ' origin / master ' into master - next
apple/swift
f0937a2cbcdee72f5520993c0a593d1744fe190a
2019-05-12T18:49:49Z
mmm a / samples / dnn / face_detector / deploy . prototxt <nl> ppp b / samples / dnn / face_detector / deploy . prototxt <nl> layer { <nl> } <nl> code_type : CENTER_SIZE <nl> keep_top_k : 200 <nl> - confidence_threshold : 0 . 01 <nl> + confidence_threshold : 0 . 2 <nl> + clip : 1 <nl> } <nl> } <nl>
Add clip to deploy . prototxt
opencv/opencv
97681d0607e9fe25b05cd0ae7a3ce7dfeb13c55b
2019-06-30T16:39:05Z
mmm a / buildscripts / resmokelib / config . py <nl> ppp b / buildscripts / resmokelib / config . py <nl> <nl> " variant_name " : None , <nl> " version_id " : None , <nl> <nl> - # Cedar options . <nl> - " cedar_url " : " cedar . mongodb . com " , <nl> - " cedar_rpc_port " : " 7070 " , <nl> - <nl> # WiredTiger options . <nl> " wt_coll_config " : None , <nl> " wt_engine_config " : None , <nl> def resolve ( self ) : <nl> # The root url of the buildlogger server . <nl> BUILDLOGGER_URL = None <nl> <nl> - # URL to connect to the Cedar service . <nl> - CEDAR_URL = None <nl> - <nl> - # Cedar gRPC service port . <nl> - CEDAR_RPC_PORT = None <nl> - <nl> # Root directory for where resmoke . py puts directories containing data files of mongod ' s it starts , <nl> # as well as those started by individual tests . <nl> DBPATH_PREFIX = None <nl> def resolve ( self ) : <nl> # or subprocess32 module to spawn threads . If jasper , resmoke uses the jasper module . <nl> SPAWN_USING = None <nl> <nl> - # The connection string to the jasper service , populated when the service is <nl> - # initialized in TestRunner . <nl> - JASPER_CONNECTION_STR = None <nl> - <nl> # If true , the launching of jobs is staggered in resmoke . py . <nl> STAGGER_JOBS = None <nl> <nl> mmm a / buildscripts / resmokelib / configure_resmoke . py <nl> ppp b / buildscripts / resmokelib / configure_resmoke . py <nl> def _merge_set_params ( param_list ) : <nl> _config . EVERGREEN_VARIANT_NAME = config . pop ( " variant_name " ) <nl> _config . EVERGREEN_VERSION_ID = config . pop ( " version_id " ) <nl> <nl> - # Cedar options . <nl> - _config . CEDAR_URL = config . pop ( " cedar_url " ) <nl> - _config . CEDAR_RPC_PORT = config . pop ( " cedar_rpc_port " ) <nl> - <nl> # Archival options . Archival is enabled only when running on evergreen . <nl> if not _config . EVERGREEN_TASK_ID : <nl> _config . ARCHIVE_FILE = None <nl> mmm a / buildscripts / resmokelib / core / jasper_process . py <nl> ppp b / buildscripts / resmokelib / core / jasper_process . py <nl> <nl> except ImportError : <nl> pass <nl> <nl> - from buildscripts . resmokelib import config <nl> from buildscripts . resmokelib import errors <nl> from buildscripts . resmokelib . core import process as _process <nl> - from buildscripts . resmokelib . logging . jasper_logger import get_logger_config <nl> from buildscripts . resmokelib . testing . fixtures import interface as fixture_interface <nl> <nl> <nl> class Process ( _process . Process ) : <nl> " " " Class for spawning a process using mongodb / jasper . " " " <nl> <nl> - pb = None <nl> - rpc = None <nl> + jasper_pb2 = None <nl> + jasper_pb2_grpc = None <nl> + connection_str = None <nl> <nl> - def __init__ ( self , logger , args , env = None , env_vars = None , job_num = None , test_id = None ) : # pylint : disable = too - many - arguments <nl> + def __init__ ( self , logger , args , env = None , env_vars = None ) : <nl> " " " Initialize the process with the specified logger , arguments , and environment . " " " <nl> _process . Process . __init__ ( self , logger , args , env = env , env_vars = env_vars ) <nl> self . _id = None <nl> - self . job_num = job_num <nl> - self . test_id = test_id <nl> - self . _stub = self . rpc . JasperProcessManagerStub ( <nl> - grpc . insecure_channel ( config . JASPER_CONNECTION_STR ) ) <nl> + self . _stub = self . jasper_pb2_grpc . JasperProcessManagerStub ( <nl> + grpc . insecure_channel ( self . connection_str ) ) <nl> self . _return_code = None <nl> <nl> def start ( self ) : <nl> " " " Start the process and the logger pipes for its stdout and stderr . " " " <nl> - logger = get_logger_config ( group_id = self . job_num , test_id = self . test_id , <nl> - process_name = self . args [ 0 ] ) <nl> - output_opts = self . pb . OutputOptions ( loggers = [ logger ] ) <nl> - create_options = self . pb . CreateOptions ( <nl> + log_format = self . jasper_pb2 . LogFormat . Value ( " LOGFORMATPLAIN " ) <nl> + log_level = self . jasper_pb2 . LogLevel ( ) <nl> + buffered = self . jasper_pb2 . BufferOptions ( ) <nl> + base_opts = self . jasper_pb2 . BaseOptions ( format = log_format , level = log_level , buffer = buffered ) <nl> + log_opts = self . jasper_pb2 . InheritedLoggerOptions ( base = base_opts ) <nl> + logger = self . jasper_pb2 . LoggerConfig ( ) <nl> + logger . inherited . CopyFrom ( log_opts ) <nl> + <nl> + output_opts = self . jasper_pb2 . OutputOptions ( loggers = [ logger ] ) <nl> + create_options = self . jasper_pb2 . CreateOptions ( <nl> args = self . args , <nl> environment = self . env , <nl> override_environ = True , <nl> def start ( self ) : <nl> <nl> val = self . _stub . Create ( create_options ) <nl> self . pid = val . pid <nl> - self . _id = self . pb . JasperProcessID ( value = val . id ) <nl> + self . _id = self . jasper_pb2 . JasperProcessID ( value = val . id ) <nl> self . _return_code = None <nl> <nl> def stop ( self , mode = None ) : <nl> def stop ( self , mode = None ) : <nl> mode = fixture_interface . TeardownMode . TERMINATE <nl> <nl> if mode = = fixture_interface . TeardownMode . KILL : <nl> - signal = self . pb . Signals . Value ( " KILL " ) <nl> + signal = self . jasper_pb2 . Signals . Value ( " KILL " ) <nl> elif mode = = fixture_interface . TeardownMode . TERMINATE : <nl> - signal = self . pb . Signals . Value ( " TERMINATE " ) <nl> + signal = self . jasper_pb2 . Signals . Value ( " TERMINATE " ) <nl> elif mode = = fixture_interface . TeardownMode . ABORT : <nl> - signal = self . pb . Signals . Value ( " ABRT " ) <nl> + signal = self . jasper_pb2 . Signals . Value ( " ABRT " ) <nl> else : <nl> raise errors . ProcessError ( " Process wrapper given unrecognized teardown mode : " + <nl> mode . value ) <nl> <nl> - signal_process = self . pb . SignalProcess ( ProcessID = self . _id , signal = signal ) <nl> + signal_process = self . jasper_pb2 . SignalProcess ( ProcessID = self . _id , signal = signal ) <nl> val = self . _stub . Signal ( signal_process ) <nl> if not val . success \ <nl> and " cannot signal a process that has terminated " not in val . text \ <nl> def wait ( self , timeout = None ) : <nl> " " " Wait until process has terminated and all output has been consumed by the logger pipes . " " " <nl> if self . _return_code is None : <nl> wait = self . _stub . Wait ( self . _id ) <nl> + if not wait . success : <nl> + raise OSError ( " Failed to wait on process with pid { } : { } . " . format ( <nl> + self . pid , wait . text ) ) <nl> self . _return_code = wait . exit_code <nl> return self . _return_code <nl> mmm a / buildscripts / resmokelib / core / programs . py <nl> ppp b / buildscripts / resmokelib / core / programs . py <nl> def make_process ( * args , * * kwargs ) : <nl> process_cls = process . Process <nl> if config . SPAWN_USING = = " jasper " : <nl> process_cls = jasper_process . Process <nl> - else : <nl> - # remove jasper process specific args <nl> - kwargs . pop ( " job_num " , None ) <nl> - kwargs . pop ( " test_id " , None ) <nl> <nl> # Add the current working directory and / data / multiversion to the PATH . <nl> env_vars = kwargs . get ( " env_vars " , { } ) . copy ( ) <nl> def mongos_program ( logger , executable = None , process_kwargs = None , * * kwargs ) : <nl> return make_process ( logger , args , * * process_kwargs ) <nl> <nl> <nl> - def mongo_shell_program ( # pylint : disable = too - many - arguments , too - many - branches , too - many - locals , too - many - statements <nl> - logger , job_num = None , test_id = None , executable = None , connection_string = None , filename = None , <nl> - process_kwargs = None , * * kwargs ) : <nl> + def mongo_shell_program ( # pylint : disable = too - many - branches , too - many - locals , too - many - statements <nl> + logger , executable = None , connection_string = None , filename = None , process_kwargs = None , <nl> + * * kwargs ) : <nl> " " " Return a Process instance that starts a mongo shell . <nl> <nl> The shell is started with the given connection string and arguments constructed from ' kwargs ' . <nl> def mongo_shell_program ( # pylint : disable = too - many - arguments , too - many - branches <nl> _set_keyfile_permissions ( test_data ) <nl> <nl> process_kwargs = utils . default_if_none ( process_kwargs , { } ) <nl> - process_kwargs [ " job_num " ] = job_num <nl> - process_kwargs [ " test_id " ] = test_id <nl> return make_process ( logger , args , * * process_kwargs ) <nl> <nl> <nl> deleted file mode 100644 <nl> index abc3269b734e . . 000000000000 <nl> mmm a / buildscripts / resmokelib / logging / jasper_logger . py <nl> ppp / dev / null <nl> <nl> - " " " Jasper logging handlers and helpers . " " " <nl> - <nl> - import os <nl> - <nl> - from buildscripts . resmokelib import config <nl> - <nl> - <nl> - def get_logger_config ( group_id = " " , test_id = " " , process_name = " " ) : <nl> - " " " Return the jasper logger config . " " " <nl> - <nl> - import jasper . jasper_pb2 as pb <nl> - <nl> - username = os . getenv ( " CEDAR_USERNAME " , default = " " ) <nl> - api_key = os . getenv ( " CEDAR_API_KEY " , default = " " ) <nl> - <nl> - logger_config = pb . LoggerConfig ( ) <nl> - log_level = pb . LogLevel ( threshold = 30 , default = 30 ) <nl> - log_format = pb . LogFormat . Value ( " LOGFORMATPLAIN " ) <nl> - <nl> - if config . EVERGREEN_TASK_ID and group_id : <nl> - buildlogger_info = pb . BuildloggerV3Info ( <nl> - project = config . EVERGREEN_PROJECT_NAME , version = config . EVERGREEN_VERSION_ID , <nl> - variant = config . EVERGREEN_VARIANT_NAME , task_name = config . EVERGREEN_TASK_NAME , <nl> - task_id = config . EVERGREEN_TASK_ID , execution = config . EVERGREEN_EXECUTION , <nl> - test_name = str ( test_id ) , process_name = process_name , format = log_format , tags = [ <nl> - str ( group_id ) <nl> - ] , base_address = config . CEDAR_URL , rpc_port = config . CEDAR_RPC_PORT , username = username , <nl> - api_key = api_key ) <nl> - buildlogger_options = pb . BuildloggerV3Options ( buildloggerv3 = buildlogger_info , <nl> - level = log_level ) <nl> - logger_config . buildloggerv3 . CopyFrom ( buildlogger_options ) <nl> - else : <nl> - buffered = pb . BufferOptions ( ) <nl> - base_opts = pb . BaseOptions ( format = log_format , level = log_level , buffer = buffered ) <nl> - log_opts = pb . DefaultLoggerOptions ( base = base_opts ) <nl> - logger_config . default . CopyFrom ( log_opts ) <nl> - <nl> - return logger_config <nl> mmm a / buildscripts / resmokelib / run / __init__ . py <nl> ppp b / buildscripts / resmokelib / run / __init__ . py <nl> <nl> _INTERNAL_OPTIONS_TITLE = " Internal Options " <nl> _BENCHMARK_ARGUMENT_TITLE = " Benchmark / Benchrun test options " <nl> _EVERGREEN_ARGUMENT_TITLE = " Evergreen options " <nl> - _CEDAR_ARGUMENT_TITLE = " Cedar options " <nl> <nl> <nl> class TestRunner ( Subcommand ) : # pylint : disable = too - many - instance - attributes <nl> def _setup_jasper ( self ) : <nl> from jasper import jasper_pb2 <nl> from jasper import jasper_pb2_grpc <nl> <nl> - jasper_process . Process . pb = jasper_pb2 <nl> - jasper_process . Process . rpc = jasper_pb2_grpc <nl> + jasper_process . Process . jasper_pb2 = jasper_pb2 <nl> + jasper_process . Process . jasper_pb2_grpc = jasper_pb2_grpc <nl> <nl> jasper_port = config . BASE_PORT - 1 <nl> jasper_conn_str = " localhost : % d " % jasper_port <nl> + jasper_process . Process . connection_str = jasper_conn_str <nl> jasper_command = [ <nl> curator_path , " jasper " , " service " , " run " , " rpc " , " - - port " , <nl> str ( jasper_port ) <nl> ] <nl> self . _jasper_server = process . Process ( self . _resmoke_logger , jasper_command ) <nl> self . _jasper_server . start ( ) <nl> - config . JASPER_CONNECTION_STR = jasper_conn_str <nl> <nl> channel = grpc . insecure_channel ( jasper_conn_str ) <nl> grpc . channel_ready_future ( channel ) . result ( ) <nl> def _add_run ( cls , subparsers ) : # pylint : disable = too - many - statements <nl> evergreen_options . add_argument ( " - - versionId " , dest = " version_id " , metavar = " VERSION_ID " , <nl> help = " Sets the version ID of the task . " ) <nl> <nl> - cedar_options = parser . add_argument_group ( <nl> - title = _CEDAR_ARGUMENT_TITLE , <nl> - description = ( " Options used to propagate Cedar service connection information . " ) ) <nl> - <nl> - cedar_options . add_argument ( " - - cedarURL " , dest = " cedar_url " , metavar = " CEDAR_URL " , <nl> - help = ( " The URL of the Cedar service . " ) ) <nl> - <nl> - cedar_options . add_argument ( " - - cedarRPCPort " , dest = " cedar_rpc_port " , <nl> - metavar = " CEDAR_RPC_PORT " , <nl> - help = ( " The RPC port of the Cedar service . " ) ) <nl> - <nl> benchmark_options = parser . add_argument_group ( <nl> title = _BENCHMARK_ARGUMENT_TITLE , <nl> description = " Options for running Benchmark / Benchrun tests " ) <nl> mmm a / buildscripts / resmokelib / testing / report . py <nl> ppp b / buildscripts / resmokelib / testing / report . py <nl> def startTest ( self , test ) : # pylint : disable = invalid - name <nl> test_info . url_endpoint = url_endpoint <nl> if self . logging_prefix is not None : <nl> test_logger . info ( self . logging_prefix ) <nl> - # Set job_num in test . <nl> - test . job_num = self . job_num <nl> <nl> test . override_logger ( test_logger ) <nl> test_info . start_time = time . time ( ) <nl> mmm a / buildscripts / resmokelib / testing / testcases / jstest . py <nl> ppp b / buildscripts / resmokelib / testing / testcases / jstest . py <nl> def _get_data_dir ( self , global_vars ) : <nl> <nl> def _make_process ( self ) : <nl> return core . programs . mongo_shell_program ( <nl> - self . logger , job_num = self . fixture . job_num , test_id = self . _id , <nl> - executable = self . shell_executable , filename = self . js_filename , <nl> + self . logger , executable = self . shell_executable , filename = self . js_filename , <nl> connection_string = self . fixture . get_driver_connection_url ( ) , * * self . shell_options ) <nl> <nl> <nl> mmm a / etc / evergreen . yml <nl> ppp b / etc / evergreen . yml <nl> functions : <nl> # Windows path separator <nl> toolchain_txt = " $ pip_dir / toolchain - requirements . txt " <nl> $ { activate_virtualenv } <nl> - packager_arch = " $ { packager_arch } " <nl> - if [ [ $ packager_arch ! = " arm64 " ] ] ; then <nl> - # For now , skip upgrading pip on ARM variants due to setup tools <nl> - # issue . <nl> - python - m pip install - - upgrade pip <nl> - fi <nl> python - m pip install - r " $ toolchain_txt " - q <nl> python - m pip freeze > pip - requirements . txt <nl> <nl> functions : <nl> working_dir : src <nl> shell : bash <nl> script : | <nl> - # Export these before verbose is set to avoid sharing sensitive info . <nl> - export CEDAR_USERNAME = $ { cedar_user } <nl> - export CEDAR_API_KEY = $ { cedar_api_key } <nl> - <nl> set - o errexit <nl> set - o verbose <nl> <nl> mmm a / etc / pip / components / resmoke . req <nl> ppp b / etc / pip / components / resmoke . req <nl> shrub . py = = 1 . 1 . 0 <nl> ocspresponder = = 0 . 5 . 0 <nl> flask = = 1 . 1 . 1 <nl> ocspbuilder = = 0 . 10 . 2 <nl> - grpcio = = 1 . 28 . 1 ; platform_machine = = " x86_64 " <nl> - grpcio - tools = = 1 . 28 . 1 ; platform_machine = = " x86_64 " <nl> - googleapis - common - protos = = 1 . 51 . 0 ; platform_machine = = " x86_64 " <nl> + # TODO : uncomment these lines with SERVER - 48156 <nl> + # grpcio = = 1 . 28 . 1 ; platform_machine ! = " x86_64 " <nl> + # grpcio - tools = = 1 . 28 . 1 ; platform_machine ! = " x86_64 " <nl> + # googleapis - common - protos = = 1 . 51 . 0 ; platform_machine ! = " x86_64 " <nl> blackduck = = 0 . 0 . 51 <nl> PyGithub = = 1 . 53 <nl> \ No newline at end of file <nl>
Revert " SERVER - 49504 : Allow resmoke ' s mongo shell to log to Jasper "
mongodb/mongo
2c50126f91f069b62bdb5c420aca8761e7486845
2020-12-07T19:21:59Z
mmm a / tensorflow / go / op / wrappers . go <nl> ppp b / tensorflow / go / op / wrappers . go <nl> func DepthwiseConv2dNativeBackpropFilterDataFormat ( value string ) DepthwiseConv2d <nl> / / element on that dimension . The dimension order is determined by the value of <nl> / / ` data_format ` , see above for details . Dilations in the batch and depth <nl> / / dimensions must be 1 . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func DepthwiseConv2dNativeBackpropFilterDilations ( value [ ] int64 ) DepthwiseConv2dNativeBackpropFilterAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func SampleDistortedBoundingBoxV2Seed2 ( value int64 ) SampleDistortedBoundingBoxV2 <nl> / / <nl> / / value : The cropped area of the image must have an aspect ratio = <nl> / / width / height within this range . <nl> - / / If not specified , defaults to { f : 0 . 75 f : 1 . 33 } <nl> + / / If not specified , defaults to { f : 0 . 75 f : 1 . 33 } <nl> func SampleDistortedBoundingBoxV2AspectRatioRange ( value [ ] float32 ) SampleDistortedBoundingBoxV2Attr { <nl> return func ( m optionalAttr ) { <nl> m [ " aspect_ratio_range " ] = value <nl> func SampleDistortedBoundingBoxV2AspectRatioRange ( value [ ] float32 ) SampleDistort <nl> / / <nl> / / value : The cropped area of the image must contain a fraction of the <nl> / / supplied image within this range . <nl> - / / If not specified , defaults to { f : 0 . 05 f : 1 } <nl> + / / If not specified , defaults to { f : 0 . 05 f : 1 } <nl> func SampleDistortedBoundingBoxV2AreaRange ( value [ ] float32 ) SampleDistortedBoundingBoxV2Attr { <nl> return func ( m optionalAttr ) { <nl> m [ " area_range " ] = value <nl> func SampleDistortedBoundingBoxMinObjectCovered ( value float32 ) SampleDistortedBo <nl> / / <nl> / / value : The cropped area of the image must have an aspect ratio = <nl> / / width / height within this range . <nl> - / / If not specified , defaults to { f : 0 . 75 f : 1 . 33 } <nl> + / / If not specified , defaults to { f : 0 . 75 f : 1 . 33 } <nl> func SampleDistortedBoundingBoxAspectRatioRange ( value [ ] float32 ) SampleDistortedBoundingBoxAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " aspect_ratio_range " ] = value <nl> func SampleDistortedBoundingBoxAspectRatioRange ( value [ ] float32 ) SampleDistorted <nl> / / <nl> / / value : The cropped area of the image must contain a fraction of the <nl> / / supplied image within this range . <nl> - / / If not specified , defaults to { f : 0 . 05 f : 1 } <nl> + / / If not specified , defaults to { f : 0 . 05 f : 1 } <nl> func SampleDistortedBoundingBoxAreaRange ( value [ ] float32 ) SampleDistortedBoundingBoxAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " area_range " ] = value <nl> func ImageSummaryMaxImages ( value int64 ) ImageSummaryAttr { <nl> / / ImageSummaryBadColor sets the optional bad_color attribute to value . <nl> / / <nl> / / value : Color to use for pixels with non - finite values . <nl> - / / If not specified , defaults to { dtype : DT_UINT8 tensor_shape : { dim : { size : 4 } } int_val : 255 int_val : 0 int_val : 0 int_val : 255 } <nl> + / / If not specified , defaults to { dtype : DT_UINT8 tensor_shape : { dim : { size : 4 } } int_val : 255 int_val : 0 int_val : 0 int_val : 255 } <nl> func ImageSummaryBadColor ( value tf . Tensor ) ImageSummaryAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " bad_color " ] = value <nl> func Conv3DBackpropFilterV2DataFormat ( value string ) Conv3DBackpropFilterV2Attr { <nl> / / filter element on that dimension . The dimension order is determined by the <nl> / / value of ` data_format ` , see above for details . Dilations in the batch and <nl> / / depth dimensions must be 1 . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 i : 1 } <nl> func Conv3DBackpropFilterV2Dilations ( value [ ] int64 ) Conv3DBackpropFilterV2Attr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func Conv2DBackpropInputDataFormat ( value string ) Conv2DBackpropInputAttr { <nl> / / element on that dimension . The dimension order is determined by the value of <nl> / / ` data_format ` , see above for details . Dilations in the batch and depth <nl> / / dimensions must be 1 . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func Conv2DBackpropInputDilations ( value [ ] int64 ) Conv2DBackpropInputAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func Conv2DDataFormat ( value string ) Conv2DAttr { <nl> / / filter element on that dimension . The dimension order is determined by the <nl> / / value of ` data_format ` , see above for details . Dilations in the batch and <nl> / / depth dimensions must be 1 . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func Conv2DDilations ( value [ ] int64 ) Conv2DAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func QuantizedDepthwiseConv2DWithBiasAndReluAndRequantizeOutType ( value tf . DataTy <nl> / / QuantizedDepthwiseConv2DWithBiasAndReluAndRequantizeDilations sets the optional dilations attribute to value . <nl> / / <nl> / / value : List of dilation values . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func QuantizedDepthwiseConv2DWithBiasAndReluAndRequantizeDilations ( value [ ] int64 ) QuantizedDepthwiseConv2DWithBiasAndReluAndRequantizeAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func QuantizedDepthwiseConv2DWithBiasAndReluOutType ( value tf . DataType ) Quantized <nl> / / QuantizedDepthwiseConv2DWithBiasAndReluDilations sets the optional dilations attribute to value . <nl> / / <nl> / / value : List of dilation values . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func QuantizedDepthwiseConv2DWithBiasAndReluDilations ( value [ ] int64 ) QuantizedDepthwiseConv2DWithBiasAndReluAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func QuantizedDepthwiseConv2DWithBiasOutType ( value tf . DataType ) QuantizedDepthwi <nl> / / QuantizedDepthwiseConv2DWithBiasDilations sets the optional dilations attribute to value . <nl> / / <nl> / / value : List of dilation values . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func QuantizedDepthwiseConv2DWithBiasDilations ( value [ ] int64 ) QuantizedDepthwiseConv2DWithBiasAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func QuantizedDepthwiseConv2DOutType ( value tf . DataType ) QuantizedDepthwiseConv2D <nl> / / QuantizedDepthwiseConv2DDilations sets the optional dilations attribute to value . <nl> / / <nl> / / value : List of dilation values . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func QuantizedDepthwiseConv2DDilations ( value [ ] int64 ) QuantizedDepthwiseConv2DAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func QuantizedConv2DPerChannelOutType ( value tf . DataType ) QuantizedConv2DPerChann <nl> / / QuantizedConv2DPerChannelDilations sets the optional dilations attribute to value . <nl> / / <nl> / / value : list of dilation values . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func QuantizedConv2DPerChannelDilations ( value [ ] int64 ) QuantizedConv2DPerChannelAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func Conv3DBackpropInputV2DataFormat ( value string ) Conv3DBackpropInputV2Attr { <nl> / / filter element on that dimension . The dimension order is determined by the <nl> / / value of ` data_format ` , see above for details . Dilations in the batch and <nl> / / depth dimensions must be 1 . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 i : 1 } <nl> func Conv3DBackpropInputV2Dilations ( value [ ] int64 ) Conv3DBackpropInputV2Attr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func AvgPool3DGrad ( scope * Scope , orig_input_shape tf . Output , grad tf . Output , ksi <nl> type Conv3DBackpropFilterAttr func ( optionalAttr ) <nl> <nl> / / Conv3DBackpropFilterDilations sets the optional dilations attribute to value . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 i : 1 } <nl> func Conv3DBackpropFilterDilations ( value [ ] int64 ) Conv3DBackpropFilterAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func DepthwiseConv2dNativeBackpropInputDataFormat ( value string ) DepthwiseConv2dN <nl> / / element on that dimension . The dimension order is determined by the value of <nl> / / ` data_format ` , see above for details . Dilations in the batch and depth <nl> / / dimensions must be 1 . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func DepthwiseConv2dNativeBackpropInputDilations ( value [ ] int64 ) DepthwiseConv2dNativeBackpropInputAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func DepthwiseConv2dNativeBackpropInput ( scope * Scope , input_sizes tf . Output , fil <nl> type Conv3DBackpropInputAttr func ( optionalAttr ) <nl> <nl> / / Conv3DBackpropInputDilations sets the optional dilations attribute to value . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 i : 1 } <nl> func Conv3DBackpropInputDilations ( value [ ] int64 ) Conv3DBackpropInputAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func DepthwiseConv2dNativeDataFormat ( value string ) DepthwiseConv2dNativeAttr { <nl> / / element on that dimension . The dimension order is determined by the value of <nl> / / ` data_format ` , see above for details . Dilations in the batch and depth <nl> / / dimensions must be 1 . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func DepthwiseConv2dNativeDilations ( value [ ] int64 ) DepthwiseConv2dNativeAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func QuantizedConv2DOutType ( value tf . DataType ) QuantizedConv2DAttr { <nl> / / filter element on that dimension . The dimension order is determined by the <nl> / / value of ` data_format ` , see above for details . Dilations in the batch and <nl> / / depth dimensions must be 1 . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func QuantizedConv2DDilations ( value [ ] int64 ) QuantizedConv2DAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func Conv3DDataFormat ( value string ) Conv3DAttr { <nl> / / filter element on that dimension . The dimension order is determined by the <nl> / / value of ` data_format ` , see above for details . Dilations in the batch and <nl> / / depth dimensions must be 1 . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 i : 1 } <nl> func Conv3DDilations ( value [ ] int64 ) Conv3DAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl> func Conv2DBackpropFilterDataFormat ( value string ) Conv2DBackpropFilterAttr { <nl> / / element on that dimension . The dimension order is determined by the value of <nl> / / ` data_format ` , see above for details . Dilations in the batch and depth <nl> / / dimensions must be 1 . <nl> - / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> + / / If not specified , defaults to { i : 1 i : 1 i : 1 i : 1 } <nl> func Conv2DBackpropFilterDilations ( value [ ] int64 ) Conv2DBackpropFilterAttr { <nl> return func ( m optionalAttr ) { <nl> m [ " dilations " ] = value <nl>
Go : Update generated wrapper functions for TensorFlow ops .
tensorflow/tensorflow
961a678760143af95b4bfaec3c96bc2bff220a48
2020-02-21T14:51:00Z
mmm a / modules / gpu / test / nvidia / TestHaarCascadeApplication . cpp <nl> ppp b / modules / gpu / test / nvidia / TestHaarCascadeApplication . cpp <nl> bool TestHaarCascadeApplication : : process ( ) <nl> <nl> _FPU_SETCW ( fpu_oldcw ) ; / / restore old cw <nl> # else <nl> + # ifndef _WIN64 <nl> Ncv32u fpu_oldcw , fpu_cw ; <nl> _controlfp_s ( & fpu_cw , 0 , 0 ) ; <nl> fpu_oldcw = fpu_cw ; <nl> _controlfp_s ( & fpu_cw , _PC_24 , _MCW_PC ) ; <nl> + # endif <nl> ncvStat = ncvApplyHaarClassifierCascade_host ( <nl> h_integralImage , h_rectStdDev , h_pixelMask , <nl> detectionsOnThisScale_h , <nl> haar , h_HaarStages , h_HaarNodes , h_HaarFeatures , false , <nl> searchRoiU , 1 , 1 . 0f ) ; <nl> ncvAssertReturn ( ncvStat = = NCV_SUCCESS , false ) ; <nl> + # ifndef _WIN64 <nl> _controlfp_s ( & fpu_cw , fpu_oldcw , _MCW_PC ) ; <nl> # endif <nl> + # endif <nl> <nl> # endif <nl> NCV_SKIP_COND_END <nl>
fixed ( HaarCascadeApplication GPU test crash )
opencv/opencv
e1fd68b21e514bd96658421329be78a226549e46
2012-03-31T23:49:35Z
mmm a / caffe2 / operators / filler_op . h <nl> ppp b / caffe2 / operators / filler_op . h <nl> class LengthsRangeFillOp : public Operator < Context > { <nl> <nl> bool RunOnDevice ( ) override { <nl> auto & input = Input ( 0 ) ; <nl> - <nl> + auto * output = Output ( 0 ) ; <nl> auto * input_data = input . template data < int32_t > ( ) ; <nl> <nl> CAFFE_ENFORCE_EQ ( input . dim ( ) , 1 , " Input must be a vector . " ) ; <nl> <nl> auto len_sum = std : : accumulate ( input_data , input_data + input . numel ( ) , 0 ) ; <nl> <nl> - auto * output = Output ( 0 , { len_sum } , at : : dtype < int32_t > ( ) ) ; <nl> + output - > Resize ( len_sum ) ; <nl> auto * output_data = output - > template mutable_data < int32_t > ( ) ; <nl> <nl> int32_t offset = 0 ; <nl> mmm a / caffe2 / operators / find_duplicate_elements_op . h <nl> ppp b / caffe2 / operators / find_duplicate_elements_op . h <nl> class FindDuplicateElementsOp final : public Operator < Context > { <nl> } <nl> <nl> const auto dupSize = dupIndices . size ( ) ; <nl> - <nl> - auto * output = Output ( 0 , { dupSize } , at : : dtype < int64_t > ( ) ) ; <nl> + auto * output = Output ( 0 ) ; <nl> + output - > Resize ( dupSize ) ; <nl> auto * out_ptr = output - > template mutable_data < int64_t > ( ) ; <nl> for ( int64_t i = 0 ; i < dupSize ; + + i ) { <nl> out_ptr [ i ] = dupIndices [ i ] ; <nl> mmm a / caffe2 / operators / flexible_top_k . cc <nl> ppp b / caffe2 / operators / flexible_top_k . cc <nl> template < typename T , class Context > <nl> bool FlexibleTopKOp < T , Context > : : RunOnDevice ( ) { <nl> auto & input = Input ( 0 ) ; <nl> auto & k = Input ( 1 ) ; <nl> + auto * values = Output ( 0 ) ; <nl> + auto * indices = Output ( 1 ) ; <nl> <nl> const T * input_data = input . template data < T > ( ) ; <nl> const int64_t * k_data = k . template data < int64_t > ( ) ; <nl> bool FlexibleTopKOp < T , Context > : : RunOnDevice ( ) { <nl> k_data [ i ] ) ; <nl> output_size + = k_data [ i ] ; <nl> } <nl> - auto * values = Output ( 0 , { output_size } , at : : dtype < T > ( ) ) ; <nl> - auto * indices = Output ( 1 , { output_size } , at : : dtype < int64_t > ( ) ) ; <nl> + values - > Resize ( output_size ) ; <nl> + indices - > Resize ( output_size ) ; <nl> T * values_data = values - > template mutable_data < T > ( ) ; <nl> int64_t * indices_data = indices - > template mutable_data < int64_t > ( ) ; <nl> <nl> bool FlexibleTopKGradientOp < T , Context > : : RunOnDevice ( ) { <nl> auto & k = Input ( 1 ) ; <nl> auto & values = Input ( 2 ) ; <nl> auto & indices = Input ( 3 ) ; <nl> + auto * output = Output ( 0 ) ; <nl> <nl> const int64_t * k_data = k . template data < int64_t > ( ) ; <nl> const T * values_data = values . template data < T > ( ) ; <nl> bool FlexibleTopKGradientOp < T , Context > : : RunOnDevice ( ) { <nl> / / Resize output tensors to be as orignial_input size and initialized with 0 <nl> CAFFE_ENFORCE_GT ( original_input . dim ( ) , 0 ) ; <nl> vector < int64_t > original_dims = original_input . sizes ( ) . vec ( ) ; <nl> - auto * output = Output ( 0 , original_dims , at : : dtype < T > ( ) ) ; <nl> + output - > Resize ( original_dims ) ; <nl> T * output_data = output - > template mutable_data < T > ( ) ; <nl> math : : Set < T , Context > ( <nl> output - > numel ( ) , static_cast < T > ( 0 ) , output_data , & context_ ) ; <nl> mmm a / caffe2 / operators / fully_connected_op . h <nl> ppp b / caffe2 / operators / fully_connected_op . h <nl> class FullyConnectedOp final : public Operator < Context > { <nl> const auto & X = Input ( 0 ) ; <nl> const auto & W = Input ( 1 ) ; <nl> const auto & b = Input ( 2 ) ; <nl> - <nl> + auto * Y = Output ( 0 ) ; <nl> CAFFE_ENFORCE ( b . dim ( ) = = 1 , b . dim ( ) ) ; <nl> / / batch size <nl> const auto canonical_axis = X . canonical_axis_index ( axis_ ) ; <nl> class FullyConnectedOp final : public Operator < Context > { <nl> DCHECK_LE ( canonical_axis + 1 , Y_shape_cache_ . size ( ) ) ; <nl> Y_shape_cache_ . resize ( canonical_axis + 1 ) ; <nl> Y_shape_cache_ [ canonical_axis ] = N ; <nl> - auto * Y = Output ( 0 , Y_shape_cache_ , at : : dtype < T_Y > ( ) ) ; <nl> + Y - > Resize ( Y_shape_cache_ ) ; <nl> CAFFE_ENFORCE ( M * N = = Y - > numel ( ) , dimErrorString ( ) ) ; <nl> <nl> if ( X . numel ( ) = = 0 ) { <nl> class FullyConnectedGradientOp : public Operator < Context > { <nl> CAFFE_ENFORCE ( K * N = = W . numel ( ) , dimErrorString ( ) ) ; <nl> <nl> auto * dW = Output ( 0 ) ; <nl> - <nl> + auto * db = Output ( 1 ) ; <nl> dW - > ResizeLike ( W ) ; <nl> - auto * db = Output ( 1 , { N } , at : : dtype < T_DB > ( ) ) ; <nl> + db - > Resize ( N ) ; <nl> <nl> if ( X . numel ( ) = = 0 ) { <nl> / / generate a zero blob for db and dW when X is empty <nl> mmm a / caffe2 / operators / fused_rowwise_8bit_conversion_ops . h <nl> ppp b / caffe2 / operators / fused_rowwise_8bit_conversion_ops . h <nl> class FloatToFused8BitRowwiseQuantizedOp : public Operator < Context > { <nl> CAFFE_ENFORCE ( IS_LITTLE_ENDIAN , " Unsupported endianness " ) ; <nl> <nl> const auto & input = Input ( DATA_FLOAT ) ; <nl> + auto * output = Output ( DATA_FUSED_SCALE_BIAS_INT8 ) ; <nl> <nl> const auto input_rows = input . size ( 0 ) ; <nl> const auto input_columns = input . size ( 1 ) ; <nl> class FloatToFused8BitRowwiseQuantizedOp : public Operator < Context > { <nl> / / | number_of_columns | 4B | 4B | <nl> const std : : vector < int64_t > output_dimensions = { input_rows , <nl> input_columns + 8 } ; <nl> - auto * output = Output ( <nl> - DATA_FUSED_SCALE_BIAS_INT8 , output_dimensions , at : : dtype < uint8_t > ( ) ) ; <nl> + output - > Resize ( output_dimensions ) ; <nl> <nl> const auto * input_data = input . template data < T > ( ) ; <nl> auto * output_data = output - > template mutable_data < uint8_t > ( ) ; <nl> class Fused8BitRowwiseQuantizedToFloatOp : public Operator < Context > { <nl> CAFFE_ENFORCE ( IS_LITTLE_ENDIAN , " Unsupported endianness " ) ; <nl> <nl> const auto & input = Input ( DATA_FUSED_SCALE_BIAS_INT8 ) ; <nl> + auto * output = Output ( DATA_FLOAT ) ; <nl> <nl> const auto input_rows = input . size ( 0 ) ; <nl> const auto input_columns = input . size ( 1 ) ; <nl> class Fused8BitRowwiseQuantizedToFloatOp : public Operator < Context > { <nl> / / input_columns is the number of values in the original row . <nl> const std : : vector < int64_t > output_dimensions = { input_rows , <nl> input_columns - 8 } ; <nl> - auto * output = Output ( DATA_FLOAT , output_dimensions , at : : dtype < T > ( ) ) ; <nl> + output - > Resize ( output_dimensions ) ; <nl> const auto output_columns = output - > size ( 1 ) ; <nl> <nl> const auto * input_data = input . template data < uint8_t > ( ) ; <nl> mmm a / caffe2 / operators / fused_rowwise_random_quantization_ops . cc <nl> ppp b / caffe2 / operators / fused_rowwise_random_quantization_ops . cc <nl> bool FloatToFusedRandRowwiseQuantizedOp < Context > : : RunOnDevice ( ) { <nl> CAFFE_ENFORCE ( IS_LITTLE_ENDIAN , " Unsupported endianness " ) ; <nl> <nl> const auto & input = Input ( DATA_FLOAT ) ; <nl> + auto * output = Output ( DATA_FUSED_QUANTIZED ) ; <nl> <nl> CAFFE_ENFORCE_EQ ( <nl> input . dim ( ) , <nl> bool FloatToFusedRandRowwiseQuantizedOp < Context > : : RunOnDevice ( ) { <nl> size_t segment_size = ( input_columns + data_per_byte - 1 ) / data_per_byte ; <nl> const std : : vector < int64_t > output_dimensions = { <nl> input_rows , 10 + static_cast < int64_t > ( segment_size ) } ; <nl> - auto * output = <nl> - Output ( DATA_FUSED_QUANTIZED , output_dimensions , at : : dtype < uint8_t > ( ) ) ; <nl> + output - > Resize ( output_dimensions ) ; <nl> <nl> const auto * input_data = input . template data < float > ( ) ; <nl> auto * output_data = output - > template mutable_data < uint8_t > ( ) ; <nl> bool FusedRandRowwiseQuantizedToFloatOp < Context > : : RunOnDevice ( ) { <nl> CAFFE_ENFORCE ( IS_LITTLE_ENDIAN , " Unsupported endianness " ) ; <nl> <nl> const auto & input = Input ( DATA_FUSED_QUANTIZED ) ; <nl> - <nl> + auto * output = Output ( DATA_FLOAT ) ; <nl> CAFFE_ENFORCE_EQ ( input . dim ( ) , 2 , " Expect input to be a matrix . " ) ; <nl> CAFFE_ENFORCE_GE ( <nl> input . numel ( ) , <nl> bool FusedRandRowwiseQuantizedToFloatOp < Context > : : RunOnDevice ( ) { <nl> const size_t output_columns = ( input_columns - 10 ) * ( 8 / bitwidth ) - tail ; <nl> const std : : vector < int64_t > output_dimensions = { <nl> input_rows , static_cast < int64_t > ( output_columns ) } ; <nl> - auto * output = Output ( DATA_FLOAT , output_dimensions , at : : dtype < float > ( ) ) ; <nl> + output - > Resize ( output_dimensions ) ; <nl> auto * output_data = output - > template mutable_data < float > ( ) ; <nl> for ( size_t row = 0 ; row < input_rows ; + + row ) { <nl> math : : decompress_and_dequantize ( <nl> mmm a / caffe2 / operators / gather_fused_8bit_rowwise_op . h <nl> ppp b / caffe2 / operators / gather_fused_8bit_rowwise_op . h <nl> class GatherFused8BitRowwiseOp : public Operator < Context > { <nl> bool DoRunWithType ( ) { <nl> const auto & data = Input ( DATA ) ; <nl> const auto & indices = Input ( INDICES ) ; <nl> + auto * output = Output ( 0 ) ; <nl> <nl> CAFFE_ENFORCE_EQ ( data . dim ( ) , 2 , " DATA must be a matrix " ) ; <nl> CAFFE_ENFORCE_EQ ( indices . dim ( ) , 1 , " INDICES must be a vector " ) ; <nl> class GatherFused8BitRowwiseOp : public Operator < Context > { <nl> / / Subtract 8 from the # columns of data for the 4 bytes for scale and 4 <nl> / / bytes for bias that we use in the fused representation ( per row ) . <nl> const std : : vector < int64_t > shape = { indices . size ( 0 ) , data . size ( 1 ) - 8 } ; <nl> - auto * output = Output ( 0 , shape , at : : dtype < float > ( ) ) ; <nl> + output - > Resize ( shape ) ; <nl> <nl> int block_size = shape [ 1 ] ; <nl> auto block_bytesize = data . size_from_dim ( 1 ) * data . dtype ( ) . itemsize ( ) ; <nl> mmm a / caffe2 / operators / generate_proposals_op . cc <nl> ppp b / caffe2 / operators / generate_proposals_op . cc <nl> bool GenerateProposalsOp < CPUContext > : : RunOnDevice ( ) { <nl> const auto & bbox_deltas = Input ( 1 ) ; <nl> const auto & im_info_tensor = Input ( 2 ) ; <nl> const auto & anchors = Input ( 3 ) ; <nl> + auto * out_rois = Output ( 0 ) ; <nl> + auto * out_rois_probs = Output ( 1 ) ; <nl> <nl> CAFFE_ENFORCE_EQ ( scores . dim ( ) , 4 , scores . dim ( ) ) ; <nl> CAFFE_ENFORCE ( scores . template IsType < float > ( ) , scores . dtype ( ) . name ( ) ) ; <nl> bool GenerateProposalsOp < CPUContext > : : RunOnDevice ( ) { <nl> im_info_tensor . size ( 1 ) ) ; <nl> <nl> const int roi_col_count = box_dim + 1 ; <nl> - auto * out_rois = Output ( 0 , { 0 , roi_col_count } , at : : dtype < float > ( ) ) ; <nl> - auto * out_rois_probs = Output ( 1 , { 0 } , at : : dtype < float > ( ) ) ; <nl> + out_rois - > Resize ( 0 , roi_col_count ) ; <nl> + out_rois_probs - > Resize ( 0 ) ; <nl> <nl> std : : vector < ERArrXXf > im_boxes ( num_images ) ; <nl> std : : vector < EArrXf > im_probs ( num_images ) ; <nl> mmm a / caffe2 / operators / glu_op . h <nl> ppp b / caffe2 / operators / glu_op . h <nl> class GluOp final : public Operator < Context > { <nl> <nl> bool RunOnDevice ( ) { <nl> auto & X = Input ( 0 ) ; <nl> - <nl> + auto * Y = Output ( 0 ) ; <nl> vector < int64_t > Yshape ; <nl> Yshape . insert ( Yshape . end ( ) , X . sizes ( ) . begin ( ) , X . sizes ( ) . end ( ) ) ; <nl> const int split_index = dim_ = = - 1 ? Yshape . size ( ) - 1 : dim_ ; <nl> class GluOp final : public Operator < Context > { <nl> const int M = X . size_to_dim ( split_index ) ; <nl> const int N = X . size_from_dim ( split_index + 1 ) ; <nl> Yshape [ split_index ] = split_dim_size ; <nl> - auto * Y = Output ( 0 , Yshape , at : : dtype < T > ( ) ) ; <nl> + Y - > Resize ( Yshape ) ; <nl> ComputeGlu ( <nl> M , <nl> split_dim_size , <nl> mmm a / caffe2 / operators / group_norm_op . h <nl> ppp b / caffe2 / operators / group_norm_op . h <nl> class GroupNormOp final : public Operator < Context > { <nl> T * mu_data = nullptr ; <nl> T * rsig_data = nullptr ; <nl> if ( OutputSize ( ) = = 3 ) { <nl> - auto * mu = Output ( MU , { N , G } , at : : dtype < T > ( ) ) ; <nl> - auto * rsig = Output ( INV_SIGMA , { N , G } , at : : dtype < T > ( ) ) ; <nl> + auto * mu = Output ( MU ) ; <nl> + auto * rsig = Output ( INV_SIGMA ) ; <nl> + mu - > Resize ( N , G ) ; <nl> + rsig - > Resize ( N , G ) ; <nl> mu_data = mu - > template mutable_data < T > ( ) ; <nl> rsig_data = rsig - > template mutable_data < T > ( ) ; <nl> } else { <nl> mmm a / caffe2 / operators / h_softmax_op . cc <nl> ppp b / caffe2 / operators / h_softmax_op . cc <nl> bool HSoftmaxOp < float , CPUContext > : : RunOnDevice ( ) { <nl> const auto & W = Input ( 1 ) ; <nl> const auto & b = Input ( 2 ) ; <nl> auto & label = Input ( 3 ) ; <nl> + auto * Y = Output ( 0 ) ; <nl> + auto * intermediate_output = Output ( 1 ) ; <nl> <nl> / / Batch size <nl> int M = X . dim ( ) > 1 ? X . dim32 ( 0 ) : 1 ; <nl> bool HSoftmaxOp < float , CPUContext > : : RunOnDevice ( ) { <nl> / / Sum of output dimensions of all hierarchy nodes <nl> int N = W . dim32 ( 0 ) ; <nl> CAFFE_ENFORCE_EQ ( N , b . dim32 ( 0 ) ) ; <nl> - auto * Y = Output ( 0 , { M } , at : : dtype < float > ( ) ) ; <nl> + Y - > Resize ( M ) ; <nl> auto * Ydata = Y - > template mutable_data < float > ( ) ; <nl> math : : Set < float , CPUContext > ( M , 0 . f , Ydata , & context_ ) ; <nl> const auto * labeldata = label . data < int > ( ) ; <nl> <nl> auto hierarchy = getHierarchyForLabels ( M , labeldata , hierarchy_all_map_ ) ; <nl> int int_output_size = getIntermediateOutputSize ( labeldata , M , hierarchy ) ; <nl> - auto * intermediate_output = Output ( 1 , { int_output_size } , at : : dtype < float > ( ) ) ; <nl> + intermediate_output - > Resize ( int_output_size ) ; <nl> float * int_output_data = intermediate_output - > template mutable_data < float > ( ) ; <nl> int int_output_offset = 0 ; <nl> <nl> bool HSoftmaxSearchOp < float , CPUContext > : : RunOnDevice ( ) { <nl> auto & X = Input ( 0 ) ; <nl> const auto & W = Input ( 1 ) ; <nl> const auto & b = Input ( 2 ) ; <nl> - <nl> + auto * Y_names = Output ( 0 ) ; <nl> + auto * Y_scores = Output ( 1 ) ; <nl> / / Batch size <nl> int M = X . dim ( ) > 1 ? X . dim32 ( 0 ) : 1 ; <nl> / / Input feature dimension <nl> bool HSoftmaxSearchOp < float , CPUContext > : : RunOnDevice ( ) { <nl> / / Sum of output dimensions of all hierarchy nodes <nl> int N = W . dim32 ( 0 ) ; <nl> CAFFE_ENFORCE ( N = = b . dim32 ( 0 ) , " mismatch between Weight and Bias . " ) ; <nl> - auto * Y_names = Output ( 0 , { M , top_n_ } , at : : dtype < string > ( ) ) ; <nl> - auto * Y_scores = Output ( 1 , { M , top_n_ } , at : : dtype < float > ( ) ) ; <nl> + Y_names - > Resize ( M , top_n_ ) ; <nl> + Y_scores - > Resize ( M , top_n_ ) ; <nl> <nl> if ( bias_multiplier_ . numel ( ) ! = M ) { <nl> bias_multiplier_ . Resize ( M ) ; <nl> bool HSoftmaxSearchOp < float , CPUContext > : : RunOnDevice ( ) { <nl> template < typename T , class Context > <nl> bool HuffmanTreeHierarchyOp < T , Context > : : RunOnDevice ( ) { <nl> const auto & Y = Input ( 0 ) ; <nl> - <nl> + auto treeOutput = Output ( 0 ) ; <nl> CAFFE_ENFORCE_EQ ( Y . dim ( ) , 1 , " Input labels must be a vector . " ) ; <nl> const auto y_data = Y . template data < T > ( ) ; <nl> - auto treeOutput = Output ( 0 , { 1 } , at : : dtype < string > ( ) ) ; <nl> + treeOutput - > Resize ( 1 ) ; <nl> std : : vector < int > labelCounts ; <nl> labelCounts . resize ( num_classes_ , 0 ) ; <nl> for ( int i = 0 ; i < Y . dim32 ( 0 ) ; + + i ) { <nl> mmm a / caffe2 / operators / heatmap_max_keypoint_op . cc <nl> ppp b / caffe2 / operators / heatmap_max_keypoint_op . cc <nl> template < > <nl> bool HeatmapMaxKeypointOp < float , CPUContext > : : RunOnDevice ( ) { <nl> const auto & heatmaps_in = Input ( 0 ) ; <nl> const auto & bboxes_in = Input ( 1 ) ; <nl> + auto * keypoints_out = Output ( 0 ) ; <nl> <nl> CAFFE_ENFORCE_EQ ( heatmaps_in . dim ( ) , 4 ) ; <nl> const int N = heatmaps_in . dim32 ( 0 ) ; <nl> bool HeatmapMaxKeypointOp < float , CPUContext > : : RunOnDevice ( ) { <nl> } / * otherwise not initialized * / <nl> <nl> / / Resize and wrap outputs in Eigen <nl> - auto * keypoints_out = Output ( 0 , { N , 4 , keypoint_count } , at : : dtype < float > ( ) ) ; <nl> + keypoints_out - > Resize ( N , 4 , keypoint_count ) ; <nl> Eigen : : Map < ERArrXXf > keypoints ( <nl> keypoints_out - > mutable_data < float > ( ) , N , 4 * keypoint_count ) ; <nl> <nl> mmm a / caffe2 / operators / im2col_op . h <nl> ppp b / caffe2 / operators / im2col_op . h <nl> class Im2ColOp final : public Operator < Context > { <nl> <nl> bool RunOnDevice ( ) override { <nl> auto & X = Input ( 0 ) ; <nl> - <nl> + auto * Y = Output ( 0 ) ; <nl> CAFFE_ENFORCE ( 4 = = X . dim ( ) ) ; <nl> <nl> int N = 0 , C = 0 , H = 0 , W = 0 ; <nl> class Im2ColOp final : public Operator < Context > { <nl> <nl> switch ( order_ ) { <nl> case StorageOrder : : NCHW : { <nl> - auto * Y = Output ( <nl> - 0 , <nl> - std : : vector < int64_t > { N , C * kernel_h_ * kernel_w_ , out_h , out_w } , <nl> - at : : dtype < T > ( ) ) ; <nl> + Y - > Resize ( <nl> + std : : vector < int64_t > { N , C * kernel_h_ * kernel_w_ , out_h , out_w } ) ; <nl> <nl> const size_t dx = X . numel ( ) / N ; <nl> const size_t dy = Y - > numel ( ) / N ; <nl> class Im2ColOp final : public Operator < Context > { <nl> } <nl> } ; break ; <nl> case StorageOrder : : NHWC : { <nl> - auto * Y = Output ( <nl> - 0 , <nl> - std : : vector < int64_t > { N , out_h , out_w , kernel_h_ * kernel_w_ * C } , <nl> - at : : dtype < T > ( ) ) ; <nl> + Y - > Resize ( <nl> + std : : vector < int64_t > { N , out_h , out_w , kernel_h_ * kernel_w_ * C } ) ; <nl> <nl> const size_t dx = X . numel ( ) / N ; <nl> const size_t dy = Y - > numel ( ) / N ; <nl> mmm a / caffe2 / operators / index_ops . cc <nl> ppp b / caffe2 / operators / index_ops . cc <nl> class IndexSizeOp : public Operator < CPUContext > { <nl> <nl> bool RunOnDevice ( ) override { <nl> auto & base = OperatorBase : : Input < std : : unique_ptr < IndexBase > > ( 0 ) ; <nl> - <nl> - auto * out = Output ( 0 , std : : vector < int64_t > { } , at : : dtype < int64_tValue > ( ) ) ; <nl> + auto * out = Output ( 0 ) ; <nl> + out - > Resize ( std : : vector < int64_t > { } ) ; <nl> * out - > template mutable_data < int64_tValue > ( ) = base - > Size ( ) ; <nl> return true ; <nl> } <nl> mmm a / caffe2 / operators / integral_image_op . cc <nl> ppp b / caffe2 / operators / integral_image_op . cc <nl> using ConstEigenMatrixMapRowMajor = Eigen : : Map < <nl> template < > <nl> bool IntegralImageOp < float , CPUContext > : : RunOnDevice ( ) { <nl> const auto & X = Input ( 0 ) ; <nl> - <nl> + auto * Y = Output ( 0 ) ; <nl> CAFFE_ENFORCE_EQ ( X . dim ( ) , 4 , " Only supports 4D tensors for the momement " ) ; <nl> <nl> vector < int64_t > out_shape ( X . sizes ( ) . vec ( ) ) ; <nl> out_shape [ 2 ] + = 1 ; / / H + 1 output size <nl> out_shape [ 3 ] + = 1 ; / / W + 1 output size <nl> - auto * Y = Output ( 0 , out_shape , at : : dtype < float > ( ) ) ; <nl> + Y - > Resize ( out_shape ) ; <nl> const int ind = X . dim32 ( 0 ) ; <nl> const int chans = X . dim32 ( 1 ) ; <nl> const int rows_in = X . dim32 ( 2 ) ; <nl> mmm a / caffe2 / operators / is_empty_op . h <nl> ppp b / caffe2 / operators / is_empty_op . h <nl> class IsEmptyOp : public Operator < Context > { <nl> <nl> bool RunOnDevice ( ) override { <nl> auto & input = Input ( 0 ) ; <nl> - <nl> - auto * output = Output ( 0 , std : : vector < int64_t > { } , at : : dtype < bool > ( ) ) ; <nl> + auto * output = Output ( 0 ) ; <nl> + output - > Resize ( std : : vector < int64_t > { } ) ; <nl> * output - > template mutable_data < bool > ( ) = ( input . numel ( ) = = 0 ) ; <nl> return true ; <nl> } <nl> mmm a / caffe2 / operators / key_split_ops . h <nl> ppp b / caffe2 / operators / key_split_ops . h <nl> class KeySplitOp : public Operator < Context > { <nl> counts [ k ] + + ; <nl> } <nl> for ( int k = 0 ; k < categorical_limit_ ; k + + ) { <nl> - auto * eid = Output ( k , { counts [ k ] } , at : : dtype < int > ( ) ) ; <nl> + auto * eid = Output ( k ) ; <nl> + eid - > Resize ( counts [ k ] ) ; <nl> eids [ k ] = eid - > template mutable_data < int > ( ) ; <nl> counts [ k ] = 0 ; <nl> } <nl> mmm a / caffe2 / operators / layer_norm_op . h <nl> ppp b / caffe2 / operators / layer_norm_op . h <nl> class LayerNormOp final : public Operator < Context > { <nl> bool DoRunWithType ( ) { <nl> const auto & X = Input ( 0 ) ; <nl> auto * Y = Output ( 0 ) ; <nl> - <nl> + auto * mean = Output ( 1 ) ; <nl> + auto * sig = Output ( 2 ) ; <nl> CAFFE_ENFORCE_GE ( X . dim ( ) , 2 , " LayerNorm requires input dim > = 2 . " ) ; <nl> const int canonical_axis = X . canonical_axis_index ( axis_ ) ; <nl> const int M = X . size_to_dim ( canonical_axis ) ; <nl> const int N = X . size_from_dim ( canonical_axis ) ; <nl> Y - > ResizeLike ( X ) ; <nl> - std : : vector < int64_t > moments_dims ( <nl> + std : : vector < int > moments_dims ( <nl> X . dims ( ) . cbegin ( ) , X . dims ( ) . cbegin ( ) + canonical_axis ) ; <nl> moments_dims . push_back ( 1 ) ; <nl> - auto * mean = Output ( 1 , moments_dims , at : : dtype < T > ( ) ) ; <nl> - auto * sig = Output ( 2 , moments_dims , at : : dtype < T > ( ) ) ; <nl> + mean - > Resize ( moments_dims ) ; <nl> + sig - > Resize ( moments_dims ) ; <nl> scale_ . Resize ( M ) ; <nl> bias_ . Resize ( M ) ; <nl> <nl> mmm a / caffe2 / operators / length_split_op . h <nl> ppp b / caffe2 / operators / length_split_op . h <nl> class LengthsSplitOp final : public Operator < Context > { <nl> " ` n_split ` must contain a positive value for defined behavior . " ) ; <nl> const auto M = L . numel ( ) ; <nl> <nl> - auto * Y = Output ( 0 , { M * n_split_ } , at : : dtype < int32_t > ( ) ) ; <nl> + auto * Y = Output ( 0 ) ; <nl> + Y - > Resize ( M * n_split_ ) ; <nl> <nl> const int32_t * Ldata = L . template data < int32_t > ( ) ; <nl> int32_t * Ydata = Y - > template mutable_data < int32_t > ( ) ; <nl> mmm a / caffe2 / operators / lengths_pad_op . h <nl> ppp b / caffe2 / operators / lengths_pad_op . h <nl> class LengthsPadOp : public Operator < Context > { <nl> bool DoRunWithType ( ) { <nl> auto & data = Input ( DATA ) ; <nl> auto & lengths = Input ( LENGTHS ) ; <nl> + auto * output = Output ( 0 ) ; <nl> <nl> CAFFE_ENFORCE_EQ ( lengths . dim ( ) , 1 , " LENGTHS must be 1 - D " ) ; <nl> CAFFE_ENFORCE_GE ( data . dim ( ) , 1 , " DATA should be at least 1 - D " ) ; <nl> class LengthsPadOp : public Operator < Context > { <nl> <nl> auto shape = data . sizes ( ) . vec ( ) ; <nl> shape [ 0 ] = lengths_size * target_length_ ; <nl> - auto * output = Output ( 0 , shape , at : : dtype < T > ( ) ) ; <nl> + output - > Resize ( shape ) ; <nl> <nl> auto block_size = data . size_from_dim ( 1 ) ; <nl> auto src_data = data . template data < T > ( ) ; <nl> mmm a / caffe2 / operators / lengths_reducer_fused_8bit_rowwise_ops . h <nl> ppp b / caffe2 / operators / lengths_reducer_fused_8bit_rowwise_ops . h <nl> class SparseLengthsFused8BitRowwiseOp : public Operator < Context > { <nl> const auto & data = Input ( DATA ) ; <nl> const auto & indices = Input ( INDICES ) ; <nl> const auto & lengths = Input ( LENGTHS ) ; <nl> + auto * output = Output ( 0 ) ; <nl> <nl> CAFFE_ENFORCE_EQ ( indices . dim ( ) , 1 , " INDICES must be a vector " ) ; <nl> CAFFE_ENFORCE_EQ ( lengths . dim ( ) , 1 , " LENGTHS must be a vector " ) ; <nl> class SparseLengthsFused8BitRowwiseOp : public Operator < Context > { <nl> / / Subtract 8 from the # columns of data for the 4 bytes for scale and 4 <nl> / / bytes for bias that we use in the fused representation ( per row ) . <nl> const std : : vector < int64_t > shape = { lengths . size ( 0 ) , data . size ( 1 ) - 8 } ; <nl> - auto * output = Output ( 0 , shape , at : : dtype < float > ( ) ) ; <nl> + output - > Resize ( shape ) ; <nl> <nl> Fused8BitRowwiseEmbeddingLookup ( <nl> / * block_size = * / output - > size ( 1 ) , <nl> mmm a / caffe2 / operators / lengths_reducer_ops . h <nl> ppp b / caffe2 / operators / lengths_reducer_ops . h <nl> class CPUSparseLengthsReductionOp : public Operator < CPUContext > { <nl> const int64_t M = lengthsInput . size ( 0 ) ; <nl> const int64_t indices_size = indicesInput . numel ( ) ; <nl> <nl> + auto * output = Output ( 0 ) ; <nl> auto shape = dataInput . sizes ( ) . vec ( ) ; <nl> shape [ 0 ] = M ; <nl> - auto * output = Output ( 0 , shape , at : : dtype < T > ( ) ) ; <nl> + output - > Resize ( shape ) ; <nl> T * out_data = output - > template mutable_data < T > ( ) ; <nl> <nl> const InputType * in_data = dataInput . template data < InputType > ( ) ; <nl> mmm a / caffe2 / operators / lengths_reducer_rowwise_8bit_ops . h <nl> ppp b / caffe2 / operators / lengths_reducer_rowwise_8bit_ops . h <nl> class SparseLengths8BitsRowwiseOp : public Operator < Context > { <nl> bool DoRunWithType ( ) { <nl> auto & dataInput = Input ( DATA ) ; <nl> auto & lengthsInput = Input ( LENGTHS ) ; <nl> - <nl> + auto * output = Output ( 0 ) ; <nl> auto * scale_bias = Input ( SCALE_BIAS ) . template data < float > ( ) ; <nl> CAFFE_ENFORCE_EQ ( 1 , lengthsInput . dim ( ) , " LENGTHS must be a vector " ) ; <nl> const int64_t outputSize = lengthsInput . size ( 0 ) ; <nl> class SparseLengths8BitsRowwiseOp : public Operator < Context > { <nl> const int * lengths = lengthsInput . template data < int > ( ) ; <nl> vector < int64_t > shape = dataInput . sizes ( ) . vec ( ) ; <nl> shape [ 0 ] = outputSize ; <nl> - auto * output = Output ( 0 , shape , at : : dtype < OutDataT > ( ) ) ; <nl> + output - > Resize ( shape ) ; <nl> const float * w = nullptr ; <nl> if ( USE_WEIGHTS ) { <nl> w = Input ( WEIGHTS ) . template data < float > ( ) ; <nl> class FloatToRowwiseQuantized8BitsOp : public Operator < Context > { <nl> bool RunOnDevice ( ) override { <nl> auto & input = Input ( DATA_FLOAT ) ; <nl> auto * output = Output ( DATA_UINT8 ) ; <nl> - <nl> + auto * scale_bias = Output ( SCALE_BIAS ) ; <nl> auto * input_data = input . template data < float > ( ) ; <nl> output - > ResizeLike ( input ) ; <nl> vector < int64_t > scale_bias_dims = { input . size ( 0 ) , 2 } ; <nl> - auto * scale_bias = Output ( SCALE_BIAS , scale_bias_dims , at : : dtype < float > ( ) ) ; <nl> + scale_bias - > Resize ( scale_bias_dims ) ; <nl> auto * output_data = output - > template mutable_data < uint8_t > ( ) ; <nl> float * scale_bias_data = scale_bias - > template mutable_data < float > ( ) ; <nl> size_t n_blocks = input . size ( 0 ) ; <nl> mmm a / caffe2 / operators / lengths_top_k_op . cc <nl> ppp b / caffe2 / operators / lengths_top_k_op . cc <nl> bool LengthsTopKOp < T , Context > : : RunOnDevice ( ) { <nl> int N = Y . dim32 ( 0 ) ; <nl> const T * X_data = X . template data < T > ( ) ; <nl> const int * input_len = Y . template data < int > ( ) ; <nl> + auto * output_topk_values = Output ( TOPK_VALUES_OUT ) ; <nl> + auto * output_topk_indices = Output ( TOPK_INDICES_OUT ) ; <nl> <nl> - auto * output_topk_values = Output ( TOPK_VALUES_OUT , { N * k_ } , at : : dtype < T > ( ) ) ; <nl> - auto * output_topk_indices = <nl> - Output ( TOPK_INDICES_OUT , { N * k_ } , at : : dtype < int > ( ) ) ; <nl> + output_topk_values - > Resize ( N * k_ ) ; <nl> + output_topk_indices - > Resize ( N * k_ ) ; <nl> std : : vector < int > output_dims = std : : vector < int > ( { N , k_ } ) ; <nl> output_topk_values - > Reshape ( output_dims ) ; <nl> output_topk_indices - > Reshape ( output_dims ) ; <nl> bool LengthsTopKGradientOp < T , Context > : : RunOnDevice ( ) { <nl> auto & input_topk = Input ( DER_TOPK_IN ) ; <nl> CAFFE_ENFORCE_EQ ( <nl> input_topk . numel ( ) , N * k_ , " input_topk shape is not correct " ) ; <nl> + auto * X_out = Output ( DER_X_OUT ) ; <nl> <nl> const int * input_len_data = input_len . template data < int > ( ) ; <nl> const int * input_indices_data = input_indices . template data < int > ( ) ; <nl> bool LengthsTopKGradientOp < T , Context > : : RunOnDevice ( ) { <nl> for ( int i = 0 ; i < N ; i + + ) { <nl> num_indices + = input_len_data [ i ] ; <nl> } <nl> - auto * X_out = Output ( DER_X_OUT , { num_indices } , at : : dtype < T > ( ) ) ; <nl> + X_out - > Resize ( num_indices ) ; <nl> std : : vector < int > output_dims = std : : vector < int > ( { num_indices } ) ; <nl> X_out - > Reshape ( output_dims ) ; <nl> T * X_out_data = X_out - > template mutable_data < T > ( ) ; <nl> mmm a / caffe2 / operators / listwise_l2r_op . cc <nl> ppp b / caffe2 / operators / listwise_l2r_op . cc <nl> bool LambdaRankNdcgOp < float , CPUContext > : : RunOnDevice ( ) { <nl> auto & y = Input ( PRED ) ; <nl> auto & r = Input ( REL ) ; <nl> auto & sid = Input ( SESSION_LENS ) ; <nl> - <nl> + auto * loss = Output ( LOSS ) ; <nl> auto * dy = Output ( DPRED ) ; <nl> <nl> const auto * session_lengths = sid . template data < int > ( ) ; <nl> CAFFE_ENFORCE ( y . dim ( ) = = 1 ) ; <nl> CAFFE_ENFORCE ( y . numel ( ) = = r . numel ( ) ) ; <nl> dy - > Resize ( y . numel ( ) ) ; <nl> - auto * loss = Output ( LOSS , { sid . numel ( ) } , at : : dtype < float > ( ) ) ; <nl> + loss - > Resize ( sid . numel ( ) ) ; <nl> auto loss_vec = loss - > template mutable_data < float > ( ) ; <nl> int start_id = 0 ; <nl> for ( int i = 0 ; i < sid . numel ( ) ; i + + ) { <nl> bool LambdaRankNdcgGradientOp < float , CPUContext > : : RunOnDevice ( ) { <nl> auto & sids = Input ( SESSION_LENS ) ; <nl> auto & dy_cache = Input ( DY_CACHE ) ; <nl> auto & dLoss = Input ( DLOSS ) ; <nl> - <nl> + auto * dy = Output ( DY ) ; <nl> CAFFE_ENFORCE ( y . dim ( ) = = 1 ) ; <nl> CAFFE_ENFORCE ( dy_cache . dim ( ) = = 1 ) ; <nl> CAFFE_ENFORCE ( dy_cache . numel ( ) > 0 ) ; <nl> bool LambdaRankNdcgGradientOp < float , CPUContext > : : RunOnDevice ( ) { <nl> <nl> ConstEigenVectorArrayMap < float > dy_cache_vec ( <nl> dy_cache . template data < float > ( ) , dy_cache . numel ( ) ) ; <nl> - auto * dy = Output ( DY , { dy_cache . numel ( ) } , at : : dtype < float > ( ) ) ; <nl> + dy - > Resize ( dy_cache . numel ( ) ) ; <nl> EigenVectorArrayMap < float > dy_vec ( <nl> dy - > template mutable_data < float > ( ) , dy - > numel ( ) ) ; <nl> auto multiplier = dLoss . template data < float > ( ) ; <nl>
Revert D13007266 : [ codemod ] [ caffe2 ] Tensor construction : combine Resize + mutable_data - 2 / 4
pytorch/pytorch
3002cb2ad01ea77a8f96109cc826fcb70498b8a7
2018-11-14T00:44:33Z
mmm a / utils / build - script <nl> ppp b / utils / build - script <nl> from build_swift . build_swift import presets <nl> <nl> import six <nl> <nl> - from swift_build_support . swift_build_support import diagnostics <nl> from swift_build_support . swift_build_support import products <nl> from swift_build_support . swift_build_support import shell <nl> from swift_build_support . swift_build_support import targets <nl> BUILD_SCRIPT_IMPL = os . path . join ( <nl> # mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> # Helpers <nl> <nl> + def print_note ( message , stream = sys . stdout ) : <nl> + " " " Writes a diagnostic message to the given stream . By default this <nl> + function outputs to stdout . <nl> + " " " <nl> + <nl> + stream . write ( ' [ { } ] NOTE : { } \ n ' . format ( sys . argv [ 0 ] , message ) ) <nl> + stream . flush ( ) <nl> + <nl> + <nl> + def fatal_error ( message , stream = sys . stderr ) : <nl> + " " " Writes a message to the given stream and exits . By default this <nl> + function outputs to stderr . <nl> + " " " <nl> + <nl> + stream . write ( ' [ { } ] ERROR : { } \ n ' . format ( sys . argv [ 0 ] , message ) ) <nl> + stream . flush ( ) <nl> + sys . exit ( 1 ) <nl> + <nl> + <nl> def clean_delay ( ) : <nl> " " " Provide a short delay so accidentally invoked clean builds can be <nl> canceled . <nl> def tar ( source , destination ) : <nl> <nl> def validate_arguments ( toolchain , args ) : <nl> if toolchain . cc is None or toolchain . cxx is None : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> " can ' t find clang ( please install clang - 3 . 5 or a " <nl> " later version ) " ) <nl> <nl> if toolchain . cmake is None : <nl> - diagnostics . fatal ( " can ' t find CMake ( please install CMake ) " ) <nl> + fatal_error ( " can ' t find CMake ( please install CMake ) " ) <nl> <nl> if args . distcc : <nl> if toolchain . distcc is None : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> " can ' t find distcc ( please install distcc ) " ) <nl> if toolchain . distcc_pump is None : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> " can ' t find distcc - pump ( please install distcc - pump ) " ) <nl> <nl> if args . host_target is None or args . stdlib_deployment_targets is None : <nl> - diagnostics . fatal ( " unknown operating system " ) <nl> + fatal_error ( " unknown operating system " ) <nl> <nl> if args . symbols_package : <nl> if not os . path . isabs ( args . symbols_package ) : <nl> def validate_arguments ( toolchain , args ) : <nl> ' ( was \ ' { } \ ' ) ' . format ( args . symbols_package ) ) <nl> return 1 <nl> if not args . install_symroot : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> " - - install - symroot is required when specifying " <nl> " - - symbols - package . " ) <nl> <nl> def validate_arguments ( toolchain , args ) : <nl> args . android_icu_i18n is None or \ <nl> args . android_icu_i18n_include is None or \ <nl> args . android_icu_data is None : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> " when building for Android , - - android - ndk , " <nl> " - - android - api - level , - - android - icu - uc , " <nl> " - - android - icu - uc - include , - - android - icu - i18n , " <nl> def validate_arguments ( toolchain , args ) : <nl> has_target_needing_toolchain = \ <nl> bool ( sum ( getattr ( args , x ) for x in targets_needing_toolchain ) ) <nl> if args . legacy_impl and has_target_needing_toolchain : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> " - - legacy - impl is incompatible with building packages needing " <nl> " a toolchain ( % s ) " % " , " . join ( targets_needing_toolchain ) ) <nl> <nl> class BuildScriptInvocation ( object ) : <nl> <nl> def build_ninja ( self ) : <nl> if not os . path . exists ( self . workspace . source_dir ( " ninja " ) ) : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> " can ' t find source directory for ninja " <nl> " ( tried % s ) " % ( self . workspace . source_dir ( " ninja " ) ) ) <nl> <nl> class BuildScriptInvocation ( object ) : <nl> source_dir = self . workspace . source_dir ( product_source_name ) <nl> <nl> if not os . path . exists ( source_dir ) : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> " can ' t find source directory for % s " <nl> " ( tried % s ) " % ( product_name , source_dir ) ) <nl> <nl> class BuildScriptInvocation ( object ) : <nl> try : <nl> config = HostSpecificConfiguration ( host_target , args ) <nl> except argparse . ArgumentError as e : <nl> - exit_rejecting_arguments ( e . message ) <nl> + exit_rejecting_arguments ( six . text_type ( e ) ) <nl> <nl> # Convert into ` build - script - impl ` style variables . <nl> options [ host_target ] = { <nl> class BuildScriptInvocation ( object ) : <nl> try : <nl> config = HostSpecificConfiguration ( host_target . name , self . args ) <nl> except argparse . ArgumentError as e : <nl> - exit_rejecting_arguments ( e . message ) <nl> + exit_rejecting_arguments ( six . text_type ( e ) ) <nl> print ( " Building the standard library for : { } " . format ( <nl> " " . join ( config . swift_stdlib_build_targets ) ) ) <nl> if config . swift_test_run_targets and ( <nl> def main_preset ( ) : <nl> try : <nl> preset_parser . read_files ( args . preset_file_names ) <nl> except presets . PresetError as e : <nl> - diagnostics . fatal ( e . message ) <nl> + fatal_error ( six . text_type ( e ) ) <nl> <nl> if args . show_presets : <nl> for name in sorted ( preset_parser . preset_names , <nl> def main_preset ( ) : <nl> return 0 <nl> <nl> if not args . preset : <nl> - diagnostics . fatal ( " missing - - preset option " ) <nl> + fatal_error ( " missing - - preset option " ) <nl> <nl> args . preset_substitutions = { } <nl> for arg in args . preset_substitutions_raw : <nl> def main_preset ( ) : <nl> args . preset , <nl> vars = args . preset_substitutions ) <nl> except presets . PresetError as e : <nl> - diagnostics . fatal ( e . message ) <nl> + fatal_error ( six . text_type ( e ) ) <nl> <nl> preset_args = migration . migrate_swift_sdks ( preset . args ) <nl> <nl> if args . distcc and ( args . cmake_c_launcher or args . cmake_cxx_launcher ) : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> ' - - distcc can not be used with ' + <nl> ' - - cmake - c - launcher or - - cmake - cxx - launcher ' ) <nl> <nl> def main_preset ( ) : <nl> if args . reconfigure : <nl> build_script_args + = [ " - - reconfigure " ] <nl> <nl> - diagnostics . note ( ' using preset " { } " , which expands to \ n \ n { } \ n ' . format ( <nl> + print_note ( ' using preset " { } " , which expands to \ n \ n { } \ n ' . format ( <nl> args . preset , printable_command ) ) <nl> shell . call_without_sleeping ( build_script_args ) <nl> return 0 <nl> def main_normal ( ) : <nl> xcrun_toolchain = os . environ . get ( ' TOOLCHAINS ' , <nl> defaults . DARWIN_XCRUN_TOOLCHAIN ) <nl> <nl> - diagnostics . note ( ' Using toolchain { } ' . format ( xcrun_toolchain ) ) <nl> + print_note ( ' Using toolchain { } ' . format ( xcrun_toolchain ) ) <nl> args . darwin_xcrun_toolchain = xcrun_toolchain <nl> <nl> toolchain = host_toolchain ( xcrun_toolchain = args . darwin_xcrun_toolchain ) <nl> def main_normal ( ) : <nl> <nl> def main ( ) : <nl> if not SWIFT_SOURCE_ROOT : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> " could not infer source root directory " + <nl> " ( forgot to set $ SWIFT_SOURCE_ROOT environment variable ? ) " ) <nl> <nl> if not os . path . isdir ( SWIFT_SOURCE_ROOT ) : <nl> - diagnostics . fatal ( <nl> + fatal_error ( <nl> " source root directory \ ' " + SWIFT_SOURCE_ROOT + <nl> " \ ' does not exist " + <nl> " ( forgot to set $ SWIFT_SOURCE_ROOT environment variable ? ) " ) <nl> mmm a / utils / swift_build_support / swift_build_support / __init__ . py <nl> ppp b / utils / swift_build_support / swift_build_support / __init__ . py <nl> <nl> # utils / swift_build_support / directory as a module . <nl> # <nl> # mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> - <nl> - __all__ = [ <nl> - " cmake " , <nl> - " debug " , <nl> - " diagnostics " , <nl> - " host_specific_configuration " , <nl> - " tar " , <nl> - " targets " , <nl> - " toolchain " , <nl> - " xcrun " , <nl> - ] <nl> deleted file mode 100644 <nl> index 6ed4c2735c58 . . 000000000000 <nl> mmm a / utils / swift_build_support / swift_build_support / diagnostics . py <nl> ppp / dev / null <nl> <nl> - # swift_build_support / diagnostics . py - Diagnostic Utilities - * - python - * - <nl> - # <nl> - # This source file is part of the Swift . org open source project <nl> - # <nl> - # Copyright ( c ) 2014 - 2017 Apple Inc . and the Swift project authors <nl> - # Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> - # <nl> - # See https : / / swift . org / LICENSE . txt for license information <nl> - # See https : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> - # <nl> - # mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> - <nl> - from __future__ import print_function <nl> - <nl> - import sys <nl> - <nl> - <nl> - def note ( message ) : <nl> - " " " <nl> - note ( message ) <nl> - <nl> - Print a diagnostic notification to the standard error stream . <nl> - " " " <nl> - print ( sys . argv [ 0 ] + " : note : " + message , file = sys . stderr ) <nl> - sys . stderr . flush ( ) <nl> - <nl> - <nl> - def fatal ( message ) : <nl> - " " " <nl> - fatal ( message ) <nl> - <nl> - Raise a fatal error . <nl> - " " " <nl> - raise SystemExit ( sys . argv [ 0 ] + " : fatal error : " + message ) <nl> mmm a / utils / swift_build_support / swift_build_support / host_specific_configuration . py <nl> ppp b / utils / swift_build_support / swift_build_support / host_specific_configuration . py <nl> <nl> # <nl> # mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> <nl> + import sys <nl> from argparse import ArgumentError <nl> <nl> - import diagnostics <nl> - <nl> from . targets import StdlibDeploymentTarget <nl> <nl> <nl> def __init__ ( self , host_target , args ) : <nl> deployment_target = StdlibDeploymentTarget . get_target_for_name ( <nl> deployment_target_name ) <nl> if deployment_target is None : <nl> - diagnostics . fatal ( " unknown target : % r " % ( <nl> - deployment_target_name , ) ) <nl> + sys . stderr . write ( ' ERROR : unknown target : { } \ n ' . format ( <nl> + deployment_target_name ) ) <nl> + sys . stderr . flush ( ) <nl> + sys . exit ( 1 ) <nl> <nl> # Add the SDK to use . <nl> deployment_platform = deployment_target . platform <nl> mmm a / utils / swift_build_support / swift_build_support / shell . py <nl> ppp b / utils / swift_build_support / swift_build_support / shell . py <nl> <nl> import sys <nl> from contextlib import contextmanager <nl> <nl> - from . import diagnostics <nl> - <nl> <nl> DEVNULL = getattr ( subprocess , ' DEVNULL ' , subprocess . PIPE ) <nl> <nl> dry_run = False <nl> <nl> <nl> + def _fatal_error ( message ) : <nl> + " " " Raises a SystemExit error with the given message . <nl> + " " " <nl> + <nl> + raise SystemExit ( ' ERROR : { } \ n ' . format ( message ) ) <nl> + <nl> + <nl> def _quote ( arg ) : <nl> return pipes . quote ( str ( arg ) ) <nl> <nl> def call ( command , stderr = None , env = None , dry_run = None , echo = True ) : <nl> try : <nl> subprocess . check_call ( command , env = _env , stderr = stderr ) <nl> except subprocess . CalledProcessError as e : <nl> - diagnostics . fatal ( <nl> + _fatal_error ( <nl> " command terminated with a non - zero exit status " + <nl> str ( e . returncode ) + " , aborting " ) <nl> except OSError as e : <nl> - diagnostics . fatal ( <nl> + _fatal_error ( <nl> " could not execute ' " + quote_command ( command ) + <nl> " ' : " + e . strerror ) <nl> <nl> def capture ( command , stderr = None , env = None , dry_run = None , echo = True , <nl> return e . output <nl> if optional : <nl> return None <nl> - diagnostics . fatal ( <nl> + _fatal_error ( <nl> " command terminated with a non - zero exit status " + <nl> str ( e . returncode ) + " , aborting " ) <nl> except OSError as e : <nl> if optional : <nl> return None <nl> - diagnostics . fatal ( <nl> + _fatal_error ( <nl> " could not execute ' " + quote_command ( command ) + <nl> " ' : " + e . strerror ) <nl> <nl>
Merge remote - tracking branch ' origin / master ' into master - next
apple/swift
f6f0890010670e9ef2b66a38d8faeef7d2eb43bf
2020-02-03T01:18:49Z
mmm a / ChangeLog <nl> ppp b / ChangeLog <nl> <nl> + 2011 - 03 - 23 : Version 3 . 2 . 4 <nl> + <nl> + Added isolates which allows several V8 instances in the same process . <nl> + This is controlled through the new Isolate class in the API . <nl> + <nl> + Implemented more of EcmaScript 5 strict mode . <nl> + <nl> + Reduced the time it takes to make detailed heap snapshot . <nl> + <nl> + Added a number of commands to the ARM simulator and enhanced the ARM <nl> + disassembler . <nl> + <nl> + <nl> 2011 - 03 - 17 : Version 3 . 2 . 3 <nl> <nl> Fixed a number of crash bugs . <nl> mmm a / src / version . cc <nl> ppp b / src / version . cc <nl> <nl> / / cannot be changed without changing the SCons build script . <nl> # define MAJOR_VERSION 3 <nl> # define MINOR_VERSION 2 <nl> - # define BUILD_NUMBER 4 <nl> + # define BUILD_NUMBER 5 <nl> # define PATCH_LEVEL 0 <nl> / / Use 1 for candidates and 0 otherwise . <nl> / / ( Boolean macro values are not supported by all preprocessors . ) <nl>
Prepare push to trunk . We are now working on 3 . 2 . 5 .
v8/v8
7de048de02d8b234fd8c47f980e0514dd1ceb158
2011-03-23T09:06:13Z
mmm a / index . htm <nl> ppp b / index . htm <nl> <nl> <nl> var yAxis = new Rickshaw . Graph . Axis . Y ( { <nl> graph : graph , <nl> - tickFormat : function ( x ) { return ( x * 100 ) + ' % ' ; } , <nl> + tickFormat : function ( y ) { return ( y * 100 ) . toFixed ( 0 ) + ' % ' ; } , <nl> ticksTreatment : ticksTreatment <nl> } ) ; <nl> <nl>
Better formatting for Y axis .
mozilla/DeepSpeech
4e358fcdc2753bd273c56cda44a72784d8306e14
2016-11-14T11:34:31Z
mmm a / cmake / OpenCVModule . cmake <nl> ppp b / cmake / OpenCVModule . cmake <nl> function ( ocv_add_perf_tests ) <nl> ocv_module_include_directories ( $ { perf_deps } " $ { perf_path } " ) <nl> <nl> if ( NOT OPENCV_PERF_ $ { the_module } _SOURCES ) <nl> - file ( GLOB perf_srcs " $ { perf_path } / * . cpp " ) <nl> - file ( GLOB perf_hdrs " $ { perf_path } / * . hpp " " $ { perf_path } / * . h " ) <nl> + file ( GLOB_RECURSE perf_srcs " $ { perf_path } / * . cpp " ) <nl> + file ( GLOB_RECURSE perf_hdrs " $ { perf_path } / * . hpp " " $ { perf_path } / * . h " ) <nl> source_group ( " Src " FILES $ { perf_srcs } ) <nl> source_group ( " Include " FILES $ { perf_hdrs } ) <nl> set ( OPENCV_PERF_ $ { the_module } _SOURCES $ { perf_srcs } $ { perf_hdrs } ) <nl> function ( ocv_add_accuracy_tests ) <nl> ocv_module_include_directories ( $ { test_deps } " $ { test_path } " ) <nl> <nl> if ( NOT OPENCV_TEST_ $ { the_module } _SOURCES ) <nl> - file ( GLOB test_srcs " $ { test_path } / * . cpp " ) <nl> - file ( GLOB test_hdrs " $ { test_path } / * . hpp " " $ { test_path } / * . h " ) <nl> + file ( GLOB_RECURSE test_srcs " $ { test_path } / * . cpp " ) <nl> + file ( GLOB_RECURSE test_hdrs " $ { test_path } / * . hpp " " $ { test_path } / * . h " ) <nl> source_group ( " Src " FILES $ { test_srcs } ) <nl> source_group ( " Include " FILES $ { test_hdrs } ) <nl> set ( OPENCV_TEST_ $ { the_module } _SOURCES $ { test_srcs } $ { test_hdrs } ) <nl> mmm a / modules / core / include / opencv2 / core / mat . hpp <nl> ppp b / modules / core / include / opencv2 / core / mat . hpp <nl> CV_EXPORTS MatExpr max ( double s , const Mat & a ) ; <nl> CV_EXPORTS MatExpr abs ( const Mat & m ) ; <nl> CV_EXPORTS MatExpr abs ( const MatExpr & e ) ; <nl> <nl> + namespace traits { <nl> + <nl> + template < typename T > <nl> + struct GetMatForRead <nl> + { <nl> + } ; <nl> + template < > <nl> + struct GetMatForRead < Mat > <nl> + { <nl> + static const Mat get ( const Mat & m ) { return m ; } <nl> + } ; <nl> + template < > <nl> + struct GetMatForRead < UMat > <nl> + { <nl> + static const Mat get ( const UMat & m ) { return m . getMat ( ACCESS_READ ) ; } <nl> + } ; <nl> + <nl> + } / / namespace traits <nl> + <nl> + template < typename T > <nl> + const Mat getMatForRead ( const T & mat ) <nl> + { <nl> + return traits : : GetMatForRead < T > : : get ( mat ) ; <nl> + } <nl> + <nl> } / / cv <nl> <nl> # include " opencv2 / core / mat . inl . hpp " <nl> mmm a / modules / core / src / arithm . cpp <nl> ppp b / modules / core / src / arithm . cpp <nl> static void arithm_op ( InputArray _src1 , InputArray _src2 , OutputArray _dst , <nl> int wtype , dims1 = psrc1 - > dims ( ) , dims2 = psrc2 - > dims ( ) ; <nl> Size sz1 = dims1 < = 2 ? psrc1 - > size ( ) : Size ( ) ; <nl> Size sz2 = dims2 < = 2 ? psrc2 - > size ( ) : Size ( ) ; <nl> - bool use_opencl = ( kind1 = = _InputArray : : UMAT | | kind2 = = _InputArray : : UMAT ) & & <nl> + bool use_opencl = ( kind1 = = _InputArray : : UMAT | | kind2 = = _InputArray : : UMAT | | _dst . kind ( ) = = _OutputArray : : UMAT ) & & <nl> ocl : : useOpenCL ( ) & & dims1 < = 2 & & dims2 < = 2 ; <nl> bool src1Scalar = checkScalar ( * psrc1 , type2 , kind1 , kind2 ) ; <nl> bool src2Scalar = checkScalar ( * psrc2 , type1 , kind2 , kind1 ) ; <nl> new file mode 100644 <nl> index 00000000000 . . 24d0f7561f3 <nl> mmm / dev / null <nl> ppp b / modules / core / test / ocl / test_arithm . cpp <nl> <nl> + / * M / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + / / <nl> + / / IMPORTANT : READ BEFORE DOWNLOADING , COPYING , INSTALLING OR USING . <nl> + / / <nl> + / / By downloading , copying , installing or using the software you agree to this license . <nl> + / / If you do not agree to this license , do not download , install , <nl> + / / copy or use the software . <nl> + / / <nl> + / / <nl> + / / License Agreement <nl> + / / For Open Source Computer Vision Library <nl> + / / <nl> + / / Copyright ( C ) 2010 - 2013 , Advanced Micro Devices , Inc . , all rights reserved . <nl> + / / Third party copyrights are property of their respective owners . <nl> + / / <nl> + / / Redistribution and use in source and binary forms , with or without modification , <nl> + / / are permitted provided that the following conditions are met : <nl> + / / <nl> + / / * Redistribution ' s of source code must retain the above copyright notice , <nl> + / / this list of conditions and the following disclaimer . <nl> + / / <nl> + / / * Redistribution ' s in binary form must reproduce the above copyright notice , <nl> + / / this list of conditions and the following disclaimer in the documentation <nl> + / / and / or other materials provided with the distribution . <nl> + / / <nl> + / / * The name of the copyright holders may not be used to endorse or promote products <nl> + / / derived from this software without specific prior written permission . <nl> + / / <nl> + / / This software is provided by the copyright holders and contributors " as is " and <nl> + / / any express or implied warranties , including , but not limited to , the implied <nl> + / / warranties of merchantability and fitness for a particular purpose are disclaimed . <nl> + / / In no event shall the OpenCV Foundation or contributors be liable for any direct , <nl> + / / indirect , incidental , special , exemplary , or consequential damages <nl> + / / ( including , but not limited to , procurement of substitute goods or services ; <nl> + / / loss of use , data , or profits ; or business interruption ) however caused <nl> + / / and on any theory of liability , whether in contract , strict liability , <nl> + / / or tort ( including negligence or otherwise ) arising in any way out of <nl> + / / the use of this software , even if advised of the possibility of such damage . <nl> + / / <nl> + / / M * / <nl> + <nl> + # include " test_precomp . hpp " <nl> + # include " opencv2 / ts / ocl_test . hpp " <nl> + <nl> + # ifdef HAVE_OPENCL <nl> + <nl> + namespace cvtest { <nl> + namespace ocl { <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / ArithmTestBase / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + PARAM_TEST_CASE ( ArithmTestBase , MatDepth , Channels , bool ) <nl> + { <nl> + int depth ; <nl> + int cn ; <nl> + bool use_roi ; <nl> + cv : : Scalar val ; <nl> + <nl> + / / declare Mat + UMat mirrors <nl> + TEST_DECLARE_INPUT_PARATEMER ( src1 ) <nl> + TEST_DECLARE_INPUT_PARATEMER ( src2 ) <nl> + TEST_DECLARE_INPUT_PARATEMER ( mask ) <nl> + TEST_DECLARE_OUTPUT_PARATEMER ( dst1 ) <nl> + TEST_DECLARE_OUTPUT_PARATEMER ( dst2 ) <nl> + <nl> + virtual void SetUp ( ) <nl> + { <nl> + depth = GET_PARAM ( 0 ) ; <nl> + cn = GET_PARAM ( 1 ) ; <nl> + use_roi = GET_PARAM ( 2 ) ; <nl> + } <nl> + <nl> + virtual void generateTestData ( ) <nl> + { <nl> + const int type = CV_MAKE_TYPE ( depth , cn ) ; <nl> + <nl> + Size roiSize = randomSize ( 1 , MAX_VALUE ) ; <nl> + Border src1Border = randomBorder ( 0 , use_roi ? MAX_VALUE : 0 ) ; <nl> + randomSubMat ( src1 , src1_roi , roiSize , src1Border , type , 2 , 11 ) ; <nl> + <nl> + Border src2Border = randomBorder ( 0 , use_roi ? MAX_VALUE : 0 ) ; <nl> + randomSubMat ( src2 , src2_roi , roiSize , src2Border , type , - 1540 , 1740 ) ; <nl> + <nl> + Border dst1Border = randomBorder ( 0 , use_roi ? MAX_VALUE : 0 ) ; <nl> + randomSubMat ( dst1 , dst1_roi , roiSize , dst1Border , type , 5 , 16 ) ; <nl> + <nl> + Border dst2Border = randomBorder ( 0 , use_roi ? MAX_VALUE : 0 ) ; <nl> + randomSubMat ( dst2 , dst2_roi , roiSize , dst2Border , type , 5 , 16 ) ; <nl> + <nl> + Border maskBorder = randomBorder ( 0 , use_roi ? MAX_VALUE : 0 ) ; <nl> + randomSubMat ( mask , mask_roi , roiSize , maskBorder , CV_8UC1 , 0 , 2 ) ; <nl> + cv : : threshold ( mask , mask , 0 . 5 , 255 . , CV_8UC1 ) ; <nl> + <nl> + val = cv : : Scalar ( rng . uniform ( - 100 . 0 , 100 . 0 ) , rng . uniform ( - 100 . 0 , 100 . 0 ) , <nl> + rng . uniform ( - 100 . 0 , 100 . 0 ) , rng . uniform ( - 100 . 0 , 100 . 0 ) ) ; <nl> + <nl> + UMAT_UPLOAD_INPUT_PARAMETER ( src1 ) <nl> + UMAT_UPLOAD_INPUT_PARAMETER ( src2 ) <nl> + UMAT_UPLOAD_INPUT_PARAMETER ( mask ) <nl> + UMAT_UPLOAD_OUTPUT_PARAMETER ( dst1 ) <nl> + UMAT_UPLOAD_OUTPUT_PARAMETER ( dst2 ) <nl> + } <nl> + <nl> + void Near ( double threshold = 0 . ) <nl> + { <nl> + EXPECT_MAT_NEAR ( dst1 , udst1 , threshold ) ; <nl> + EXPECT_MAT_NEAR ( dst1_roi , udst1_roi , threshold ) ; <nl> + } <nl> + <nl> + void Near1 ( double threshold = 0 . ) <nl> + { <nl> + EXPECT_MAT_NEAR ( dst2 , udst2 , threshold ) ; <nl> + EXPECT_MAT_NEAR ( dst2_roi , udst2_roi , threshold ) ; <nl> + } <nl> + } ; <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / Add / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + typedef ArithmTestBase Add ; <nl> + <nl> + OCL_TEST_P ( Add , Mat ) <nl> + { <nl> + for ( int j = 0 ; j < test_loop_times ; j + + ) <nl> + { <nl> + generateTestData ( ) ; <nl> + <nl> + OCL_OFF ( cv : : add ( src1_roi , src2_roi , dst1_roi ) ) ; <nl> + OCL_ON ( cv : : add ( usrc1_roi , usrc2_roi , udst1_roi ) ) ; <nl> + Near ( 0 ) ; <nl> + } <nl> + } <nl> + <nl> + OCL_TEST_P ( Add , Mat_Mask ) <nl> + { <nl> + for ( int j = 0 ; j < test_loop_times ; j + + ) <nl> + { <nl> + generateTestData ( ) ; <nl> + <nl> + OCL_OFF ( cv : : add ( src1_roi , src2_roi , dst1_roi , mask_roi ) ) ; <nl> + OCL_ON ( cv : : add ( usrc1_roi , usrc2_roi , udst1_roi , umask_roi ) ) ; <nl> + Near ( 0 ) ; <nl> + } <nl> + } <nl> + <nl> + OCL_TEST_P ( Add , Scalar ) <nl> + { <nl> + for ( int j = 0 ; j < test_loop_times ; j + + ) <nl> + { <nl> + generateTestData ( ) ; <nl> + <nl> + OCL_OFF ( cv : : add ( src1_roi , val , dst1_roi ) ) ; <nl> + OCL_ON ( cv : : add ( usrc1_roi , val , udst1_roi ) ) ; <nl> + Near ( 1e - 5 ) ; <nl> + } <nl> + } <nl> + <nl> + OCL_TEST_P ( Add , Scalar_Mask ) <nl> + { <nl> + for ( int j = 0 ; j < test_loop_times ; j + + ) <nl> + { <nl> + generateTestData ( ) ; <nl> + <nl> + OCL_OFF ( cv : : add ( src1_roi , val , dst1_roi , mask_roi ) ) ; <nl> + OCL_ON ( cv : : add ( usrc1_roi , val , udst1_roi , umask_roi ) ) ; <nl> + Near ( 1e - 5 ) ; <nl> + } <nl> + } <nl> + <nl> + <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / Instantiation / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + OCL_INSTANTIATE_TEST_CASE_P ( Arithm , Add , Combine ( OCL_ALL_DEPTHS , OCL_ALL_CHANNELS , Bool ( ) ) ) ; <nl> + <nl> + } } / / namespace cvtest : : ocl <nl> + <nl> + # endif / / HAVE_OPENCL <nl> new file mode 100644 <nl> index 00000000000 . . 5c6aaef7995 <nl> mmm / dev / null <nl> ppp b / modules / ts / include / opencv2 / ts / ocl_test . hpp <nl> <nl> + / * M / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + / / <nl> + / / IMPORTANT : READ BEFORE DOWNLOADING , COPYING , INSTALLING OR USING . <nl> + / / <nl> + / / By downloading , copying , installing or using the software you agree to this license . <nl> + / / If you do not agree to this license , do not download , install , <nl> + / / copy or use the software . <nl> + / / <nl> + / / <nl> + / / License Agreement <nl> + / / For Open Source Computer Vision Library <nl> + / / <nl> + / / Copyright ( C ) 2010 - 2013 , Advanced Micro Devices , Inc . , all rights reserved . <nl> + / / Third party copyrights are property of their respective owners . <nl> + / / <nl> + / / Redistribution and use in source and binary forms , with or without modification , <nl> + / / are permitted provided that the following conditions are met : <nl> + / / <nl> + / / * Redistribution ' s of source code must retain the above copyright notice , <nl> + / / this list of conditions and the following disclaimer . <nl> + / / <nl> + / / * Redistribution ' s in binary form must reproduce the above copyright notice , <nl> + / / this list of conditions and the following disclaimer in the documentation <nl> + / / and / or other materials provided with the distribution . <nl> + / / <nl> + / / * The name of the copyright holders may not be used to endorse or promote products <nl> + / / derived from this software without specific prior written permission . <nl> + / / <nl> + / / This software is provided by the copyright holders and contributors " as is " and <nl> + / / any express or implied warranties , including , but not limited to , the implied <nl> + / / warranties of merchantability and fitness for a particular purpose are disclaimed . <nl> + / / In no event shall the OpenCV Foundation or contributors be liable for any direct , <nl> + / / indirect , incidental , special , exemplary , or consequential damages <nl> + / / ( including , but not limited to , procurement of substitute goods or services ; <nl> + / / loss of use , data , or profits ; or business interruption ) however caused <nl> + / / and on any theory of liability , whether in contract , strict liability , <nl> + / / or tort ( including negligence or otherwise ) arising in any way out of <nl> + / / the use of this software , even if advised of the possibility of such damage . <nl> + / / <nl> + / / M * / <nl> + <nl> + # ifndef __OPENCV_TS_OCL_TEST_HPP__ <nl> + # define __OPENCV_TS_OCL_TEST_HPP__ <nl> + <nl> + # ifdef HAVE_OPENCL <nl> + <nl> + # include " cvconfig . h " <nl> + # include " opencv2 / opencv_modules . hpp " <nl> + <nl> + # include " opencv2 / ts . hpp " <nl> + <nl> + # include " opencv2 / highgui . hpp " <nl> + # include " opencv2 / imgproc . hpp " <nl> + # include " opencv2 / imgproc / types_c . h " <nl> + # include " opencv2 / core / ocl . hpp " <nl> + <nl> + namespace cvtest { <nl> + namespace ocl { <nl> + <nl> + using namespace cv ; <nl> + using namespace testing ; <nl> + <nl> + extern int test_loop_times ; <nl> + <nl> + # define MAX_VALUE 357 <nl> + <nl> + # define EXPECT_MAT_NORM ( mat , eps ) \ <nl> + { \ <nl> + EXPECT_LE ( checkNorm ( mat ) , eps ) \ <nl> + } <nl> + <nl> + # define EXPECT_MAT_NEAR ( mat1 , mat2 , eps ) \ <nl> + { \ <nl> + ASSERT_EQ ( mat1 . type ( ) , mat2 . type ( ) ) ; \ <nl> + ASSERT_EQ ( mat1 . size ( ) , mat2 . size ( ) ) ; \ <nl> + EXPECT_LE ( checkNorm ( mat1 , mat2 ) , eps ) \ <nl> + < < cv : : format ( " Size : % d x % d " , mat1 . size ( ) . width , mat1 . size ( ) . height ) < < std : : endl ; \ <nl> + } <nl> + <nl> + # define EXPECT_MAT_NEAR_RELATIVE ( mat1 , mat2 , eps ) \ <nl> + { \ <nl> + ASSERT_EQ ( mat1 . type ( ) , mat2 . type ( ) ) ; \ <nl> + ASSERT_EQ ( mat1 . size ( ) , mat2 . size ( ) ) ; \ <nl> + EXPECT_LE ( checkNormRelative ( mat1 , mat2 ) , eps ) \ <nl> + < < cv : : format ( " Size : % d x % d " , mat1 . size ( ) . width , mat1 . size ( ) . height ) < < std : : endl ; \ <nl> + } <nl> + <nl> + # define EXPECT_MAT_SIMILAR ( mat1 , mat2 , eps ) \ <nl> + { \ <nl> + ASSERT_EQ ( mat1 . type ( ) , mat2 . type ( ) ) ; \ <nl> + ASSERT_EQ ( mat1 . size ( ) , mat2 . size ( ) ) ; \ <nl> + EXPECT_LE ( checkSimilarity ( mat1 , mat2 ) , eps ) ; \ <nl> + < < cv : : format ( " Size : % d x % d " , mat1 . size ( ) . width , mat1 . size ( ) . height ) < < std : : endl ; \ <nl> + } <nl> + <nl> + using perf : : MatDepth ; <nl> + using perf : : MatType ; <nl> + <nl> + # define OCL_RNG_SEED 123456 <nl> + <nl> + struct TestUtils <nl> + { <nl> + cv : : RNG rng ; <nl> + <nl> + TestUtils ( ) <nl> + { <nl> + rng = cv : : RNG ( OCL_RNG_SEED ) ; <nl> + } <nl> + <nl> + int randomInt ( int minVal , int maxVal ) <nl> + { <nl> + return rng . uniform ( minVal , maxVal ) ; <nl> + } <nl> + <nl> + double randomDouble ( double minVal , double maxVal ) <nl> + { <nl> + return rng . uniform ( minVal , maxVal ) ; <nl> + } <nl> + <nl> + double randomDoubleLog ( double minVal , double maxVal ) <nl> + { <nl> + double logMin = log ( ( double ) minVal + 1 ) ; <nl> + double logMax = log ( ( double ) maxVal + 1 ) ; <nl> + double pow = rng . uniform ( logMin , logMax ) ; <nl> + double v = exp ( pow ) - 1 ; <nl> + CV_Assert ( v > = minVal & & ( v < maxVal | | ( v = = minVal & & v = = maxVal ) ) ) ; <nl> + return v ; <nl> + } <nl> + <nl> + Size randomSize ( int minVal , int maxVal ) <nl> + { <nl> + # if 1 <nl> + return cv : : Size ( ( int ) randomDoubleLog ( minVal , maxVal ) , ( int ) randomDoubleLog ( minVal , maxVal ) ) ; <nl> + # else <nl> + return cv : : Size ( randomInt ( minVal , maxVal ) , randomInt ( minVal , maxVal ) ) ; <nl> + # endif <nl> + } <nl> + <nl> + Size randomSize ( int minValX , int maxValX , int minValY , int maxValY ) <nl> + { <nl> + # if 1 <nl> + return cv : : Size ( ( int ) randomDoubleLog ( minValX , maxValX ) , ( int ) randomDoubleLog ( minValY , maxValY ) ) ; <nl> + # else <nl> + return cv : : Size ( randomInt ( minVal , maxVal ) , randomInt ( minVal , maxVal ) ) ; <nl> + # endif <nl> + } <nl> + <nl> + Scalar randomScalar ( double minVal , double maxVal ) <nl> + { <nl> + return Scalar ( randomDouble ( minVal , maxVal ) , randomDouble ( minVal , maxVal ) , randomDouble ( minVal , maxVal ) , randomDouble ( minVal , maxVal ) ) ; <nl> + } <nl> + <nl> + Mat randomMat ( Size size , int type , double minVal , double maxVal , bool useRoi = false ) <nl> + { <nl> + RNG dataRng ( rng . next ( ) ) ; <nl> + return cvtest : : randomMat ( dataRng , size , type , minVal , maxVal , useRoi ) ; <nl> + } <nl> + <nl> + struct Border <nl> + { <nl> + int top , bot , lef , rig ; <nl> + } ; <nl> + <nl> + Border randomBorder ( int minValue = 0 , int maxValue = MAX_VALUE ) <nl> + { <nl> + Border border = { <nl> + ( int ) randomDoubleLog ( minValue , maxValue ) , <nl> + ( int ) randomDoubleLog ( minValue , maxValue ) , <nl> + ( int ) randomDoubleLog ( minValue , maxValue ) , <nl> + ( int ) randomDoubleLog ( minValue , maxValue ) <nl> + } ; <nl> + return border ; <nl> + } <nl> + <nl> + void randomSubMat ( Mat & whole , Mat & subMat , const Size & roiSize , const Border & border , int type , double minVal , double maxVal ) <nl> + { <nl> + Size wholeSize = Size ( roiSize . width + border . lef + border . rig , roiSize . height + border . top + border . bot ) ; <nl> + whole = randomMat ( wholeSize , type , minVal , maxVal , false ) ; <nl> + subMat = whole ( Rect ( border . lef , border . top , roiSize . width , roiSize . height ) ) ; <nl> + } <nl> + <nl> + / / If the two vectors are not equal , it will return the difference in vector size <nl> + / / Else it will return ( total diff of each 1 and 2 rects covered pixels ) / ( total 1 rects covered pixels ) <nl> + / / The smaller , the better matched <nl> + static double checkRectSimilarity ( cv : : Size sz , std : : vector < cv : : Rect > & ob1 , std : : vector < cv : : Rect > & ob2 ) ; <nl> + <nl> + / / ! read image from testdata folder . <nl> + <nl> + static cv : : Mat readImage ( const String & fileName , int flags = cv : : IMREAD_COLOR ) ; <nl> + static cv : : Mat readImageType ( const String & fname , int type ) ; <nl> + <nl> + static double checkNorm ( const cv : : Mat & m ) ; <nl> + static double checkNorm ( const cv : : Mat & m1 , const cv : : Mat & m2 ) ; <nl> + static double checkSimilarity ( const cv : : Mat & m1 , const cv : : Mat & m2 ) ; <nl> + static inline double checkNormRelative ( const Mat & m1 , const Mat & m2 ) <nl> + { <nl> + return cv : : norm ( m1 , m2 , cv : : NORM_INF ) / <nl> + std : : max ( ( double ) std : : numeric_limits < float > : : epsilon ( ) , <nl> + ( double ) std : : max ( cv : : norm ( m1 , cv : : NORM_INF ) , norm ( m2 , cv : : NORM_INF ) ) ) ; <nl> + } <nl> + static void showDiff ( const Mat & src , const Mat & gold , const Mat & actual , double eps , bool alwaysShow = false ) ; <nl> + <nl> + template < typename T1 > <nl> + static double checkNorm ( const T1 & m ) <nl> + { <nl> + return checkNorm ( cv : : getMatForRead ( m ) ) ; <nl> + } <nl> + template < typename T1 , typename T2 > <nl> + static double checkNorm ( const T1 & m1 , const T2 & m2 ) <nl> + { <nl> + return checkNorm ( cv : : getMatForRead ( m1 ) , cv : : getMatForRead ( m2 ) ) ; <nl> + } <nl> + template < typename T1 , typename T2 > <nl> + static double checkSimilarity ( const T1 & m1 , const T2 & m2 ) <nl> + { <nl> + return checkSimilarity ( cv : : getMatForRead ( m1 ) , cv : : getMatForRead ( m2 ) ) ; <nl> + } <nl> + template < typename T1 , typename T2 > <nl> + static inline double checkNormRelative ( const T1 & m1 , const T2 & m2 ) <nl> + { <nl> + const Mat _m1 = cv : : getMatForRead ( m1 ) ; <nl> + const Mat _m2 = cv : : getMatForRead ( m2 ) ; <nl> + return checkNormRelative ( _m1 , _m2 ) ; <nl> + } <nl> + <nl> + template < typename T1 , typename T2 , typename T3 > <nl> + static void showDiff ( const T1 & src , const T2 & gold , const T3 & actual , double eps , bool alwaysShow = false ) <nl> + { <nl> + const Mat _src = cv : : getMatForRead ( src ) ; <nl> + const Mat _gold = cv : : getMatForRead ( gold ) ; <nl> + const Mat _actual = cv : : getMatForRead ( actual ) ; <nl> + showDiff ( _src , _gold , _actual , eps , alwaysShow ) ; <nl> + } <nl> + } ; <nl> + <nl> + # define TEST_DECLARE_INPUT_PARATEMER ( name ) Mat name , name # # _roi ; UMat u # # name , u # # name # # _roi ; <nl> + # define TEST_DECLARE_OUTPUT_PARATEMER ( name ) TEST_DECLARE_INPUT_PARATEMER ( name ) <nl> + <nl> + # define UMAT_UPLOAD_INPUT_PARAMETER ( name ) \ <nl> + { \ <nl> + name . copyTo ( u # # name ) ; \ <nl> + Size wholeSize ; Point ofs ; name # # _roi . locateROI ( wholeSize , ofs ) ; \ <nl> + u # # name # # _roi = u # # name ( Rect ( ofs . x , ofs . y , name # # _roi . size ( ) . width , name # # _roi . size ( ) . height ) ) ; \ <nl> + } <nl> + # define UMAT_UPLOAD_OUTPUT_PARAMETER ( name ) UMAT_UPLOAD_INPUT_PARAMETER ( name ) <nl> + <nl> + template < typename T > <nl> + struct TSTestWithParam : public TestUtils , public : : testing : : TestWithParam < T > <nl> + { <nl> + <nl> + } ; <nl> + <nl> + # define PARAM_TEST_CASE ( name , . . . ) struct name : public TSTestWithParam < std : : tr1 : : tuple < __VA_ARGS__ > > <nl> + <nl> + # define GET_PARAM ( k ) std : : tr1 : : get < k > ( GetParam ( ) ) <nl> + <nl> + # ifndef IMPLEMENT_PARAM_CLASS <nl> + # define IMPLEMENT_PARAM_CLASS ( name , type ) \ <nl> + class name \ <nl> + { \ <nl> + public : \ <nl> + name ( type arg = type ( ) ) : val_ ( arg ) { } \ <nl> + operator type ( ) const { return val_ ; } \ <nl> + private : \ <nl> + type val_ ; \ <nl> + } ; \ <nl> + inline void PrintTo ( name param , std : : ostream * os ) \ <nl> + { \ <nl> + * os < < # name < < " ( " < < testing : : PrintToString ( static_cast < type > ( param ) ) < < " ) " ; \ <nl> + } <nl> + <nl> + IMPLEMENT_PARAM_CLASS ( Channels , int ) <nl> + # endif / / IMPLEMENT_PARAM_CLASS <nl> + <nl> + # define OCL_TEST_P TEST_P <nl> + <nl> + # define OCL_OFF ( fn ) cv : : ocl : : setUseOpenCL ( false ) ; fn <nl> + # define OCL_ON ( fn ) cv : : ocl : : setUseOpenCL ( true ) ; fn <nl> + <nl> + # define OCL_ALL_DEPTHS Values ( CV_8U , CV_8S , CV_16U , CV_16S , CV_32S , CV_32F , CV_64F ) <nl> + # define OCL_ALL_CHANNELS Values ( 1 , 2 , 3 , 4 ) <nl> + <nl> + # define OCL_INSTANTIATE_TEST_CASE_P ( prefix , test_case_name , generator ) \ <nl> + INSTANTIATE_TEST_CASE_P ( OCL_ # # prefix , test_case_name , generator ) <nl> + <nl> + } } / / namespace cvtest : : ocl <nl> + <nl> + # endif / / HAVE_OPENCL <nl> + <nl> + # endif / / __OPENCV_TS_OCL_TEST_HPP__ <nl> new file mode 100644 <nl> index 00000000000 . . d2ee771996f <nl> mmm / dev / null <nl> ppp b / modules / ts / src / ocl_test . cpp <nl> <nl> + / * M / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + / / <nl> + / / IMPORTANT : READ BEFORE DOWNLOADING , COPYING , INSTALLING OR USING . <nl> + / / <nl> + / / By downloading , copying , installing or using the software you agree to this license . <nl> + / / If you do not agree to this license , do not download , install , <nl> + / / copy or use the software . <nl> + / / <nl> + / / <nl> + / / License Agreement <nl> + / / For Open Source Computer Vision Library <nl> + / / <nl> + / / Copyright ( C ) 2010 - 2013 , Advanced Micro Devices , Inc . , all rights reserved . <nl> + / / Third party copyrights are property of their respective owners . <nl> + / / <nl> + / / Redistribution and use in source and binary forms , with or without modification , <nl> + / / are permitted provided that the following conditions are met : <nl> + / / <nl> + / / * Redistribution ' s of source code must retain the above copyright notice , <nl> + / / this list of conditions and the following disclaimer . <nl> + / / <nl> + / / * Redistribution ' s in binary form must reproduce the above copyright notice , <nl> + / / this list of conditions and the following disclaimer in the documentation <nl> + / / and / or other materials provided with the distribution . <nl> + / / <nl> + / / * The name of the copyright holders may not be used to endorse or promote products <nl> + / / derived from this software without specific prior written permission . <nl> + / / <nl> + / / This software is provided by the copyright holders and contributors " as is " and <nl> + / / any express or implied warranties , including , but not limited to , the implied <nl> + / / warranties of merchantability and fitness for a particular purpose are disclaimed . <nl> + / / In no event shall the OpenCV Foundation or contributors be liable for any direct , <nl> + / / indirect , incidental , special , exemplary , or consequential damages <nl> + / / ( including , but not limited to , procurement of substitute goods or services ; <nl> + / / loss of use , data , or profits ; or business interruption ) however caused <nl> + / / and on any theory of liability , whether in contract , strict liability , <nl> + / / or tort ( including negligence or otherwise ) arising in any way out of <nl> + / / the use of this software , even if advised of the possibility of such damage . <nl> + / / <nl> + / / M * / <nl> + <nl> + # include " precomp . hpp " <nl> + <nl> + # include " opencv2 / ts / ocl_test . hpp " <nl> + <nl> + # ifdef HAVE_OPENCL <nl> + <nl> + namespace cvtest { <nl> + namespace ocl { <nl> + <nl> + using namespace cv ; <nl> + <nl> + int test_loop_times = 1 ; / / TODO Read from command line / environment <nl> + <nl> + Mat TestUtils : : readImage ( const String & fileName , int flags ) <nl> + { <nl> + return cv : : imread ( cvtest : : TS : : ptr ( ) - > get_data_path ( ) + fileName , flags ) ; <nl> + } <nl> + <nl> + Mat TestUtils : : readImageType ( const String & fname , int type ) <nl> + { <nl> + Mat src = readImage ( fname , CV_MAT_CN ( type ) = = 1 ? cv : : IMREAD_GRAYSCALE : cv : : IMREAD_COLOR ) ; <nl> + if ( CV_MAT_CN ( type ) = = 4 ) <nl> + { <nl> + Mat temp ; <nl> + cv : : cvtColor ( src , temp , cv : : COLOR_BGR2BGRA ) ; <nl> + swap ( src , temp ) ; <nl> + } <nl> + src . convertTo ( src , CV_MAT_DEPTH ( type ) ) ; <nl> + return src ; <nl> + } <nl> + <nl> + double TestUtils : : checkNorm ( const Mat & m ) <nl> + { <nl> + return norm ( m , NORM_INF ) ; <nl> + } <nl> + <nl> + double TestUtils : : checkNorm ( const Mat & m1 , const Mat & m2 ) <nl> + { <nl> + return norm ( m1 , m2 , NORM_INF ) ; <nl> + } <nl> + <nl> + double TestUtils : : checkSimilarity ( const Mat & m1 , const Mat & m2 ) <nl> + { <nl> + Mat diff ; <nl> + matchTemplate ( m1 , m2 , diff , CV_TM_CCORR_NORMED ) ; <nl> + return std : : abs ( diff . at < float > ( 0 , 0 ) - 1 . f ) ; <nl> + } <nl> + <nl> + double TestUtils : : checkRectSimilarity ( Size sz , std : : vector < Rect > & ob1 , std : : vector < Rect > & ob2 ) <nl> + { <nl> + double final_test_result = 0 . 0 ; <nl> + size_t sz1 = ob1 . size ( ) ; <nl> + size_t sz2 = ob2 . size ( ) ; <nl> + <nl> + if ( sz1 ! = sz2 ) <nl> + { <nl> + return sz1 > sz2 ? ( double ) ( sz1 - sz2 ) : ( double ) ( sz2 - sz1 ) ; <nl> + } <nl> + else <nl> + { <nl> + if ( sz1 = = 0 & & sz2 = = 0 ) <nl> + return 0 ; <nl> + cv : : Mat cpu_result ( sz , CV_8UC1 ) ; <nl> + cpu_result . setTo ( 0 ) ; <nl> + <nl> + for ( vector < Rect > : : const_iterator r = ob1 . begin ( ) ; r ! = ob1 . end ( ) ; r + + ) <nl> + { <nl> + cv : : Mat cpu_result_roi ( cpu_result , * r ) ; <nl> + cpu_result_roi . setTo ( 1 ) ; <nl> + cpu_result . copyTo ( cpu_result ) ; <nl> + } <nl> + int cpu_area = cv : : countNonZero ( cpu_result > 0 ) ; <nl> + <nl> + cv : : Mat gpu_result ( sz , CV_8UC1 ) ; <nl> + gpu_result . setTo ( 0 ) ; <nl> + for ( vector < Rect > : : const_iterator r2 = ob2 . begin ( ) ; r2 ! = ob2 . end ( ) ; r2 + + ) <nl> + { <nl> + cv : : Mat gpu_result_roi ( gpu_result , * r2 ) ; <nl> + gpu_result_roi . setTo ( 1 ) ; <nl> + gpu_result . copyTo ( gpu_result ) ; <nl> + } <nl> + <nl> + cv : : Mat result_ ; <nl> + multiply ( cpu_result , gpu_result , result_ ) ; <nl> + int result = cv : : countNonZero ( result_ > 0 ) ; <nl> + if ( cpu_area ! = 0 & & result ! = 0 ) <nl> + final_test_result = 1 . 0 - ( double ) result / ( double ) cpu_area ; <nl> + else if ( cpu_area = = 0 & & result ! = 0 ) <nl> + final_test_result = - 1 ; <nl> + } <nl> + return final_test_result ; <nl> + } <nl> + <nl> + void TestUtils : : showDiff ( const Mat & src , const Mat & gold , const Mat & actual , double eps , bool alwaysShow ) <nl> + { <nl> + Mat diff , diff_thresh ; <nl> + absdiff ( gold , actual , diff ) ; <nl> + diff . convertTo ( diff , CV_32F ) ; <nl> + threshold ( diff , diff_thresh , eps , 255 . 0 , cv : : THRESH_BINARY ) ; <nl> + <nl> + if ( alwaysShow | | cv : : countNonZero ( diff_thresh . reshape ( 1 ) ) > 0 ) <nl> + { <nl> + # if 0 <nl> + std : : cout < < " Source : " < < std : : endl < < src < < std : : endl ; <nl> + std : : cout < < " Expected : " < < std : : endl < < gold < < std : : endl ; <nl> + std : : cout < < " Actual : " < < std : : endl < < actual < < std : : endl ; <nl> + # endif <nl> + <nl> + namedWindow ( " src " , WINDOW_NORMAL ) ; <nl> + namedWindow ( " gold " , WINDOW_NORMAL ) ; <nl> + namedWindow ( " actual " , WINDOW_NORMAL ) ; <nl> + namedWindow ( " diff " , WINDOW_NORMAL ) ; <nl> + <nl> + imshow ( " src " , src ) ; <nl> + imshow ( " gold " , gold ) ; <nl> + imshow ( " actual " , actual ) ; <nl> + imshow ( " diff " , diff ) ; <nl> + <nl> + cv : : waitKey ( ) ; <nl> + } <nl> + } <nl> + <nl> + } } / / namespace cvtest : : ocl <nl> + <nl> + # endif / / HAVE_OPENCL <nl>
ocl / core : added prototype for tests
opencv/opencv
881e837520960798b2f8c2f1944f10ca9b5aef25
2013-11-22T14:37:44Z
mmm a / dlib / gui_widgets / widgets . cpp <nl> ppp b / dlib / gui_widgets / widgets . cpp <nl> namespace dlib <nl> point p ( x , y ) ; <nl> p - = origin ; <nl> if ( zoom_in_scale ! = 1 ) <nl> - p = p / ( double ) zoom_in_scale ; <nl> + p = p / zoom_in_scale ; <nl> else if ( zoom_out_scale ! = 1 ) <nl> - p = p * ( double ) zoom_out_scale ; <nl> + p = p * zoom_out_scale ; <nl> <nl> if ( dlib : : get_rect ( img ) . contains ( p ) ) <nl> image_clicked_handler ( p , is_double_click ) ; <nl>
Fixed a problem where the pixel click location reported by
davisking/dlib
578107c3645cda81221b87f712cba24ed07e4571
2013-01-16T23:24:56Z
mmm a / cocos2dx / layers_scenes_transitions_nodes / CCTransition . cpp <nl> ppp b / cocos2dx / layers_scenes_transitions_nodes / CCTransition . cpp <nl> THE SOFTWARE . <nl> # include " CCActionTiledGrid . h " <nl> namespace cocos2d { <nl> <nl> - enum { <nl> - kSceneFade = 0xFADEFADE , <nl> - } ; <nl> + const unsigned int kSceneFade = 0xFADEFADE ; <nl> <nl> # define IMPLEMENT_TRANSITIONWITHDURATION ( _Type ) \ <nl> _Type * _Type : : transitionWithDuration ( ccTime t , CCScene * scene ) \ <nl> mmm a / cocos2dx / textures / CCTexture2D . cpp <nl> ppp b / cocos2dx / textures / CCTexture2D . cpp <nl> bool CCTexture2D : : getHasPremultipliedAlpha ( ) <nl> <nl> bool CCTexture2D : : initWithData ( const void * data , CCTexture2DPixelFormat pixelFormat , unsigned int pixelsWide , unsigned int pixelsHigh , CCSize contentSize ) <nl> { <nl> + glPixelStorei ( GL_UNPACK_ALIGNMENT , 1 ) ; <nl> glGenTextures ( 1 , & m_uName ) ; <nl> glBindTexture ( GL_TEXTURE_2D , m_uName ) ; <nl> <nl>
Merge pull request from flyingpacer / master
cocos2d/cocos2d-x
a1531cd4788f09fe5599e63bf86d57285153807e
2011-07-08T08:59:36Z
mmm a / third_party / fbgemm <nl> ppp b / third_party / fbgemm <nl> @ @ - 1 + 1 @ @ <nl> - Subproject commit 2d9c2bb4010bee5a28b688f1b239d8f390391d4d <nl> + Subproject commit e8650fd5601e28783f64f5a38541e6d562125375 <nl>
Updating submodules
pytorch/pytorch
5a58c16722749045ada77e4641e934a0fcb48c4e
2020-01-17T20:48:36Z
mmm a / src / compiler / js - operator . cc <nl> ppp b / src / compiler / js - operator . cc <nl> const Operator * JSOperatorBuilder : : Call ( size_t arity , CallFrequency frequency , <nl> VectorSlotPair const & feedback , <nl> ConvertReceiverMode convert_mode , <nl> SpeculationMode speculation_mode ) { <nl> + DCHECK_IMPLIES ( speculation_mode = = SpeculationMode : : kAllowSpeculation , <nl> + feedback . IsValid ( ) ) ; <nl> CallParameters parameters ( arity , frequency , feedback , convert_mode , <nl> speculation_mode ) ; <nl> return new ( zone ( ) ) Operator1 < CallParameters > ( / / - - <nl> const Operator * JSOperatorBuilder : : CallWithArrayLike ( CallFrequency frequency ) { <nl> const Operator * JSOperatorBuilder : : CallWithSpread ( <nl> uint32_t arity , CallFrequency frequency , VectorSlotPair const & feedback , <nl> SpeculationMode speculation_mode ) { <nl> + DCHECK_IMPLIES ( speculation_mode = = SpeculationMode : : kAllowSpeculation , <nl> + feedback . IsValid ( ) ) ; <nl> CallParameters parameters ( arity , frequency , feedback , <nl> ConvertReceiverMode : : kAny , speculation_mode ) ; <nl> return new ( zone ( ) ) Operator1 < CallParameters > ( / / - - <nl> mmm a / src / compiler / js - operator . h <nl> ppp b / src / compiler / js - operator . h <nl> class V8_EXPORT_PRIVATE JSOperatorBuilder final <nl> size_t arity , CallFrequency frequency = CallFrequency ( ) , <nl> VectorSlotPair const & feedback = VectorSlotPair ( ) , <nl> ConvertReceiverMode convert_mode = ConvertReceiverMode : : kAny , <nl> - SpeculationMode speculation_mode = SpeculationMode : : kAllowSpeculation ) ; <nl> + SpeculationMode speculation_mode = SpeculationMode : : kDisallowSpeculation ) ; <nl> const Operator * CallWithArrayLike ( CallFrequency frequency ) ; <nl> const Operator * CallWithSpread ( <nl> uint32_t arity , CallFrequency frequency = CallFrequency ( ) , <nl> VectorSlotPair const & feedback = VectorSlotPair ( ) , <nl> - SpeculationMode speculation_mode = SpeculationMode : : kAllowSpeculation ) ; <nl> + SpeculationMode speculation_mode = SpeculationMode : : kDisallowSpeculation ) ; <nl> const Operator * CallRuntime ( Runtime : : FunctionId id ) ; <nl> const Operator * CallRuntime ( Runtime : : FunctionId id , size_t arity ) ; <nl> const Operator * CallRuntime ( const Runtime : : Function * function , size_t arity ) ; <nl> mmm a / src / compiler / js - typed - lowering . cc <nl> ppp b / src / compiler / js - typed - lowering . cc <nl> Reduction JSTypedLowering : : ReduceJSCall ( Node * node ) { <nl> if ( p . convert_mode ( ) ! = convert_mode ) { <nl> NodeProperties : : ChangeOp ( <nl> node , javascript ( ) - > Call ( p . arity ( ) , p . frequency ( ) , p . feedback ( ) , <nl> - convert_mode ) ) ; <nl> + convert_mode , p . speculation_mode ( ) ) ) ; <nl> return Changed ( node ) ; <nl> } <nl> <nl> mmm a / src / feedback - vector . h <nl> ppp b / src / feedback - vector . h <nl> class FeedbackVector : public HeapObject { <nl> <nl> FeedbackSlot GetTypeProfileSlot ( ) const ; <nl> <nl> - static Handle < FeedbackVector > New ( Isolate * isolate , <nl> - Handle < SharedFunctionInfo > shared ) ; <nl> + V8_EXPORT_PRIVATE static Handle < FeedbackVector > New ( <nl> + Isolate * isolate , Handle < SharedFunctionInfo > shared ) ; <nl> <nl> static Handle < FeedbackVector > Copy ( Isolate * isolate , <nl> Handle < FeedbackVector > vector ) ; <nl> class FeedbackMetadata : public FixedArray { <nl> FeedbackSlotKind GetKind ( FeedbackSlot slot ) const ; <nl> <nl> / / If { spec } is null , then it is considered empty . <nl> - static Handle < FeedbackMetadata > New ( Isolate * isolate , <nl> - const FeedbackVectorSpec * spec = nullptr ) ; <nl> + V8_EXPORT_PRIVATE static Handle < FeedbackMetadata > New ( <nl> + Isolate * isolate , const FeedbackVectorSpec * spec = nullptr ) ; <nl> <nl> # ifdef OBJECT_PRINT <nl> / / For gdb debugging . <nl> new file mode 100644 <nl> index 00000000000 . . 0e3b6c1f550 <nl> mmm / dev / null <nl> ppp b / test / mjsunit / default - nospec . js <nl> <nl> + / / Copyright 2018 the V8 project authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . <nl> + <nl> + / / Flags : - - allow - natives - syntax - - opt - - no - always - opt <nl> + <nl> + ( ( ) = > { <nl> + function f ( a , b , c ) { <nl> + return String . prototype . indexOf . call ( a , b , c ) ; <nl> + } <nl> + f ( " abc " , " de " , 1 ) ; <nl> + f ( " abc " , " de " , 1 ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( " abc " , " de " , { } ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( " abc " , " de " , { } ) ; <nl> + assertOptimized ( f ) ; <nl> + } ) ( ) ; <nl> + <nl> + ( ( ) = > { <nl> + function f ( a , b , c ) { <nl> + return String . prototype . indexOf . apply ( a , [ b , c ] ) ; <nl> + } <nl> + f ( " abc " , " de " , 1 ) ; <nl> + f ( " abc " , " de " , 1 ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( " abc " , { } , 1 ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( " abc " , { } , 1 ) ; <nl> + assertOptimized ( f ) ; <nl> + } ) ( ) ; <nl> + <nl> + ( ( ) = > { <nl> + function f ( a , b , c ) { <nl> + return Reflect . apply ( String . prototype . indexOf , a , [ b , c ] ) ; <nl> + } <nl> + f ( " abc " , " de " , 1 ) ; <nl> + f ( " abc " , " de " , 1 ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( { } , " de " , 1 ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( { } , " de " , 1 ) ; <nl> + assertOptimized ( f ) ; <nl> + } ) ( ) ; <nl> + <nl> + ( ( ) = > { <nl> + function f ( a , b ) { <nl> + return String . fromCharCode . call ( a , b ) ; <nl> + } <nl> + f ( " abc " , 1 ) ; <nl> + f ( " abc " , 1 ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( " abc " , { } ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( { } , { } ) ; <nl> + assertOptimized ( f ) ; <nl> + } ) ( ) ; <nl> + <nl> + ( ( ) = > { <nl> + function f ( a , b ) { <nl> + return String . fromCharCode . apply ( undefined , [ b , { } ] ) ; <nl> + } <nl> + f ( " abc " , 1 ) ; <nl> + f ( " abc " , 1 ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( " abc " , { } ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( " abc " , { } ) ; <nl> + assertOptimized ( f ) ; <nl> + } ) ( ) ; <nl> + <nl> + <nl> + ( ( ) = > { <nl> + function f ( a , b ) { <nl> + return Reflect . apply ( String . fromCharCode , a , [ b , { } ] ) ; <nl> + } <nl> + f ( " abc " , 1 ) ; <nl> + f ( " abc " , 1 ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( " abc " , { } ) ; <nl> + % OptimizeFunctionOnNextCall ( f ) ; <nl> + f ( " abc " , { } ) ; <nl> + assertOptimized ( f ) ; <nl> + } ) ( ) ; <nl> mmm a / test / unittests / compiler / js - call - reducer - unittest . cc <nl> ppp b / test / unittests / compiler / js - call - reducer - unittest . cc <nl> <nl> # include " src / compiler / js - call - reducer . h " <nl> # include " src / compiler / js - graph . h " <nl> # include " src / compiler / simplified - operator . h " <nl> + # include " src / factory . h " <nl> + # include " src / feedback - vector . h " <nl> # include " src / isolate . h " <nl> # include " test / unittests / compiler / graph - unittest . h " <nl> # include " test / unittests / compiler / node - test - utils . h " <nl> class JSCallReducerTest : public TypedGraphTest { <nl> string_fnc . substr ( 1 , std : : string : : npos ) ; <nl> } <nl> <nl> + const Operator * Call ( int arity ) { <nl> + FeedbackVectorSpec spec ( zone ( ) ) ; <nl> + spec . AddCallICSlot ( ) ; <nl> + Handle < FeedbackMetadata > metadata = FeedbackMetadata : : New ( isolate ( ) , & spec ) ; <nl> + Handle < SharedFunctionInfo > shared = <nl> + isolate ( ) - > factory ( ) - > NewSharedFunctionInfo ( <nl> + isolate ( ) - > factory ( ) - > empty_string ( ) , MaybeHandle < Code > ( ) , false ) ; <nl> + shared - > set_feedback_metadata ( * metadata ) ; <nl> + Handle < FeedbackVector > vector = FeedbackVector : : New ( isolate ( ) , shared ) ; <nl> + VectorSlotPair feedback ( vector , FeedbackSlot ( 0 ) ) ; <nl> + return javascript ( ) - > Call ( arity , CallFrequency ( ) , feedback , <nl> + ConvertReceiverMode : : kAny , <nl> + SpeculationMode : : kAllowSpeculation ) ; <nl> + } <nl> + <nl> private : <nl> JSOperatorBuilder javascript_ ; <nl> CompilationDependencies deps_ ; <nl> TEST_F ( JSCallReducerTest , MathUnaryWithNumber ) { <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> Node * jsfunction = MathFunction ( fnc ) ; <nl> Node * p0 = Parameter ( Type : : Any ( ) , 0 ) ; <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 3 ) , jsfunction , UndefinedConstant ( ) , <nl> - p0 , context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 3 ) , jsfunction , UndefinedConstant ( ) , p0 , <nl> + context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl> EXPECT_THAT ( std : : string ( IrOpcode : : Mnemonic ( r . replacement ( ) - > opcode ( ) ) ) , <nl> TEST_F ( JSCallReducerTest , MathBinaryWithNumber ) { <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> Node * p0 = Parameter ( Type : : Any ( ) , 0 ) ; <nl> Node * p1 = Parameter ( Type : : Any ( ) , 0 ) ; <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 4 ) , jsfunction , UndefinedConstant ( ) , <nl> - p0 , p1 , context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 4 ) , jsfunction , UndefinedConstant ( ) , p0 , <nl> + p1 , context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl> TEST_F ( JSCallReducerTest , MathClz32WithUnsigned32 ) { <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> <nl> Node * p0 = Parameter ( Type : : Unsigned32 ( ) , 0 ) ; <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 3 ) , jsfunction , UndefinedConstant ( ) , <nl> - p0 , context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 3 ) , jsfunction , UndefinedConstant ( ) , p0 , <nl> + context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl> TEST_F ( JSCallReducerTest , MathClz32WithUnsigned32NoArg ) { <nl> Node * context = UndefinedConstant ( ) ; <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 2 ) , jsfunction , UndefinedConstant ( ) , <nl> - context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 2 ) , jsfunction , UndefinedConstant ( ) , <nl> + context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl> TEST_F ( JSCallReducerTest , MathImulWithUnsigned32 ) { <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> Node * p0 = Parameter ( Type : : Unsigned32 ( ) , 0 ) ; <nl> Node * p1 = Parameter ( Type : : Unsigned32 ( ) , 1 ) ; <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 4 ) , jsfunction , UndefinedConstant ( ) , <nl> - p0 , p1 , context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 4 ) , jsfunction , UndefinedConstant ( ) , p0 , <nl> + p1 , context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl> TEST_F ( JSCallReducerTest , MathMinWithNoArguments ) { <nl> Node * control = graph ( ) - > start ( ) ; <nl> Node * context = UndefinedConstant ( ) ; <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 2 ) , jsfunction , UndefinedConstant ( ) , <nl> - context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 2 ) , jsfunction , UndefinedConstant ( ) , <nl> + context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl> TEST_F ( JSCallReducerTest , MathMinWithNumber ) { <nl> Node * context = UndefinedConstant ( ) ; <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> Node * p0 = Parameter ( Type : : Any ( ) , 0 ) ; <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 3 ) , jsfunction , UndefinedConstant ( ) , <nl> - p0 , context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 3 ) , jsfunction , UndefinedConstant ( ) , p0 , <nl> + context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl> TEST_F ( JSCallReducerTest , MathMinWithTwoArguments ) { <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> Node * p0 = Parameter ( Type : : Any ( ) , 0 ) ; <nl> Node * p1 = Parameter ( Type : : Any ( ) , 1 ) ; <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 4 ) , jsfunction , UndefinedConstant ( ) , <nl> - p0 , p1 , context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 4 ) , jsfunction , UndefinedConstant ( ) , p0 , <nl> + p1 , context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl> TEST_F ( JSCallReducerTest , MathMaxWithNoArguments ) { <nl> Node * control = graph ( ) - > start ( ) ; <nl> Node * context = UndefinedConstant ( ) ; <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 2 ) , jsfunction , UndefinedConstant ( ) , <nl> - context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 2 ) , jsfunction , UndefinedConstant ( ) , <nl> + context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl> TEST_F ( JSCallReducerTest , MathMaxWithNumber ) { <nl> Node * context = UndefinedConstant ( ) ; <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> Node * p0 = Parameter ( Type : : Any ( ) , 0 ) ; <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 3 ) , jsfunction , UndefinedConstant ( ) , <nl> - p0 , context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 3 ) , jsfunction , UndefinedConstant ( ) , p0 , <nl> + context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl> TEST_F ( JSCallReducerTest , MathMaxWithTwoArguments ) { <nl> Node * frame_state = graph ( ) - > start ( ) ; <nl> Node * p0 = Parameter ( Type : : Any ( ) , 0 ) ; <nl> Node * p1 = Parameter ( Type : : Any ( ) , 1 ) ; <nl> - Node * call = <nl> - graph ( ) - > NewNode ( javascript ( ) - > Call ( 4 ) , jsfunction , UndefinedConstant ( ) , <nl> - p0 , p1 , context , frame_state , effect , control ) ; <nl> + Node * call = graph ( ) - > NewNode ( Call ( 4 ) , jsfunction , UndefinedConstant ( ) , p0 , <nl> + p1 , context , frame_state , effect , control ) ; <nl> Reduction r = Reduce ( call ) ; <nl> <nl> ASSERT_TRUE ( r . Changed ( ) ) ; <nl>
Reland " [ turbofan ] Disable speculation for JSCall nodes by default "
v8/v8
6be614fb2d6ef87d22a17d8850a567d240e1b504
2018-02-23T08:31:41Z
mmm a / cocos / scripting / lua - bindings / auto / api / ActionManagerEx . lua <nl> ppp b / cocos / scripting / lua - bindings / auto / api / ActionManagerEx . lua <nl> <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> - - Stop an Action with a name . < br > <nl> - - param jsonName UI file name < br > <nl> mmm param actionName action name in teh UIfile . < br > <nl> + - - param actionName action name in the UIfile . < br > <nl> - - return ActionObject which named as the param name <nl> - - @ function [ parent = # ActionManagerEx ] stopActionByName <nl> - - @ param self <nl> mmm a / cocos / scripting / lua - bindings / auto / api / ControlButton . lua <nl> ppp b / cocos / scripting / lua - bindings / auto / api / ControlButton . lua <nl> <nl> <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> - - Adjust the background image . YES by default . If the property is set to NO , the < br > <nl> mmm background will use the prefered size of the background image . <nl> + - - background will use the preferred size of the background image . <nl> - - @ function [ parent = # ControlButton ] doesAdjustBackgroundImage <nl> - - @ param self <nl> - - @ return bool # bool ret ( return value : bool ) <nl> mmm a / cocos / scripting / lua - bindings / auto / api / ControlPotentiometer . lua <nl> ppp b / cocos / scripting / lua - bindings / auto / api / ControlPotentiometer . lua <nl> <nl> - - @ return float # float ret ( return value : float ) <nl> <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> mmm Factorize the event dispath into these methods . <nl> + - - Factorize the event dispatch into these methods . <nl> - - @ function [ parent = # ControlPotentiometer ] potentiometerBegan <nl> - - @ param self <nl> - - @ param # vec2_table location <nl> mmm a / cocos / scripting / lua - bindings / auto / api / Layout . lua <nl> ppp b / cocos / scripting / lua - bindings / auto / api / Layout . lua <nl> <nl> <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> - - Removes all children from the container , and do a cleanup to all running actions depending on the cleanup parameter . < br > <nl> mmm param cleanup true if all running actions on all children nodes should be cleanup , false oterwise . < br > <nl> + - - param cleanup true if all running actions on all children nodes should be cleanup , false otherwise . < br > <nl> - - js removeAllChildren < br > <nl> - - lua removeAllChildren <nl> - - @ function [ parent = # Layout ] removeAllChildrenWithCleanup <nl> mmm a / cocos / scripting / lua - bindings / auto / api / Scale9Sprite . lua <nl> ppp b / cocos / scripting / lua - bindings / auto / api / Scale9Sprite . lua <nl> <nl> - - @ return bool # bool ret ( return value : bool ) <nl> <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> mmm brief Change the prefered size of Scale9Sprite . < br > <nl> + - - brief Change the preferred size of Scale9Sprite . < br > <nl> - - param size A delimitation zone . <nl> - - @ function [ parent = # Scale9Sprite ] setPreferredSize <nl> - - @ param self <nl> <nl> - - @ return float # float ret ( return value : float ) <nl> <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> mmm brief Query the Scale9Sprite ' s prefered size . < br > <nl> + - - brief Query the Scale9Sprite ' s preferred size . < br > <nl> - - return Scale9Sprite ' s cap inset . <nl> - - @ function [ parent = # Scale9Sprite ] getCapInsets <nl> - - @ param self <nl> <nl> - - @ return bool # bool ret ( return value : bool ) <nl> <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> mmm brief Query the Scale9Sprite ' s prefered size . < br > <nl> mmm return Scale9Sprite ' s prefered size . <nl> + - - brief Query the Scale9Sprite ' s preferred size . < br > <nl> + - - return Scale9Sprite ' s preferred size . <nl> - - @ function [ parent = # Scale9Sprite ] getPreferredSize <nl> - - @ param self <nl> - - @ return size_table # size_table ret ( return value : size_table ) <nl> <nl> - - Also , flipping the texture doesn ' t alter the anchorPoint . < br > <nl> - - If you want to flip the anchorPoint too , and / or to flip the children too use : < br > <nl> - - widget - > setScaleY ( widget - > getScaleY ( ) * - 1 ) ; < br > <nl> mmm return true if the widget is flipped vertically , flase otherwise . <nl> + - - return true if the widget is flipped vertically , false otherwise . <nl> - - @ function [ parent = # Scale9Sprite ] isFlippedY <nl> - - @ param self <nl> - - @ return bool # bool ret ( return value : bool ) <nl> mmm a / cocos / scripting / lua - bindings / auto / api / Widget . lua <nl> ppp b / cocos / scripting / lua - bindings / auto / api / Widget . lua <nl> <nl> <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> - - Sets whether the widget should be flipped vertically or not . < br > <nl> mmm param flippedY true if the widget should be flipped vertically , flase otherwise . <nl> + - - param flippedY true if the widget should be flipped vertically , false otherwise . <nl> - - @ function [ parent = # Widget ] setFlippedY <nl> - - @ param self <nl> - - @ param # bool flippedY <nl> <nl> - - param pt The point in ` Vec2 ` . < br > <nl> - - param camera The camera look at widget , used to convert GL screen point to near / far plane . < br > <nl> - - param p Point to a Vec3 for store the intersect point , if don ' t need them set to nullptr . < br > <nl> mmm return true if the point is in widget ' s content space , flase otherwise . <nl> + - - return true if the point is in widget ' s content space , false otherwise . <nl> - - @ function [ parent = # Widget ] hitTest <nl> - - @ param self <nl> - - @ param # vec2_table pt <nl> <nl> - - It not only flips the texture of the widget , but also the texture of the widget ' s children . < br > <nl> - - Also , flipping relies on widget ' s anchor point . < br > <nl> - - Internally , it just use setScaleY ( - 1 ) to flip the widget . < br > <nl> mmm return true if the widget is flipped vertically , flase otherwise . <nl> + - - return true if the widget is flipped vertically , false otherwise . <nl> - - @ function [ parent = # Widget ] isFlippedY <nl> - - @ param self <nl> - - @ return bool # bool ret ( return value : bool ) <nl> <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> - - Checks a point if in parent ' s area . < br > <nl> - - param pt A point in ` Vec2 ` . < br > <nl> mmm return true if the point is in parent ' s area , flase otherwise . <nl> + - - return true if the point is in parent ' s area , false otherwise . <nl> - - @ function [ parent = # Widget ] isClippingParentContainsPoint <nl> - - @ param self <nl> - - @ param # vec2_table pt <nl>
Merge pull request from CocosRobot / update_lua_bindings_1444440864
cocos2d/cocos2d-x
bf35655ce345a1a10943eac88433721d57fbfb8f
2015-10-10T01:44:51Z
mmm a / android / playground / app / src / main / java / com / alibaba / weex / WXApplication . java <nl> ppp b / android / playground / app / src / main / java / com / alibaba / weex / WXApplication . java <nl> <nl> <nl> import android . app . Application ; <nl> <nl> - import com . alibaba . weex . extend . Components . WTRichText ; <nl> - import com . alibaba . weex . extend . ImageAdapter ; <nl> - import com . alibaba . weex . extend . Modules . RenderModule ; <nl> - import com . alibaba . weex . extend . Modules . WXEventModule ; <nl> - import com . taobao . weex . WXEnvironment ; <nl> + import com . alibaba . weex . extend . components . WTRichText ; <nl> + import com . alibaba . weex . extend . adapter . ImageAdapter ; <nl> + import com . alibaba . weex . extend . modules . RenderModule ; <nl> + import com . alibaba . weex . extend . modules . WXEventModule ; <nl> import com . taobao . weex . WXSDKEngine ; <nl> import com . taobao . weex . common . WXException ; <nl> <nl> mmm a / android / playground / app / src / main / java / com / alibaba / weex / extend / Components / WTRichText . java <nl> ppp b / android / playground / app / src / main / java / com / alibaba / weex / extend / Components / WTRichText . java <nl> <nl> * Confidential Information and shall use it only in accordance with the terms of the license <nl> * agreement you entered into with Alibaba . com . <nl> * / <nl> - package com . alibaba . weex . extend . Components ; <nl> + package com . alibaba . weex . extend . components ; <nl> <nl> import android . os . Parcel ; <nl> import android . text . Spannable ; <nl> mmm a / android / playground / app / src / main / java / com / alibaba / weex / extend / Modules / RenderModule . java <nl> ppp b / android / playground / app / src / main / java / com / alibaba / weex / extend / Modules / RenderModule . java <nl> <nl> - package com . alibaba . weex . extend . Modules ; <nl> + package com . alibaba . weex . extend . modules ; <nl> <nl> import android . util . Log ; <nl> <nl> mmm a / android / playground / app / src / main / java / com / alibaba / weex / extend / Modules / WXEventModule . java <nl> ppp b / android / playground / app / src / main / java / com / alibaba / weex / extend / Modules / WXEventModule . java <nl> <nl> - package com . alibaba . weex . extend . Modules ; <nl> + package com . alibaba . weex . extend . modules ; <nl> <nl> import android . content . Intent ; <nl> import android . net . Uri ; <nl> similarity index 99 % <nl> rename from android / playground / app / src / main / java / com / alibaba / weex / extend / ImageAdapter . java <nl> rename to android / playground / app / src / main / java / com / alibaba / weex / extend / adapter / ImageAdapter . java <nl> mmm a / android / playground / app / src / main / java / com / alibaba / weex / extend / ImageAdapter . java <nl> ppp b / android / playground / app / src / main / java / com / alibaba / weex / extend / adapter / ImageAdapter . java <nl> <nl> - package com . alibaba . weex . extend ; <nl> + package com . alibaba . weex . extend . adapter ; <nl> <nl> import android . text . TextUtils ; <nl> import android . widget . ImageView ; <nl>
* [ android ] update rename package
apache/incubator-weex
551b9e9741dcd94e2f3f17bcee8f1cf54623e519
2016-05-31T06:50:42Z
mmm a / src / core / file_sys / registered_cache . cpp <nl> ppp b / src / core / file_sys / registered_cache . cpp <nl> InstallResult RegisteredCache : : InstallEntry ( const NSP & nsp , bool overwrite_if_ex <nl> <nl> Refresh ( ) ; <nl> if ( result ) { <nl> - return InstallResult : : ErrorAlreadyExists ; <nl> + return InstallResult : : OverwriteExisting ; <nl> } <nl> return InstallResult : : Success ; <nl> } <nl> mmm a / src / yuzu / main . cpp <nl> ppp b / src / yuzu / main . cpp <nl> InstallResult GMainWindow : : InstallNSPXCI ( const QString & filename ) { <nl> * nsp , true , qt_raw_copy ) ; <nl> if ( res = = FileSys : : InstallResult : : Success ) { <nl> return InstallResult : : Success ; <nl> - } else if ( res = = FileSys : : InstallResult : : ErrorAlreadyExists ) { <nl> + } else if ( res = = FileSys : : InstallResult : : OverwriteExisting ) { <nl> return InstallResult : : Overwrite ; <nl> } else { <nl> return InstallResult : : Failure ; <nl> InstallResult GMainWindow : : InstallNCA ( const QString & filename ) { <nl> <nl> if ( res = = FileSys : : InstallResult : : Success ) { <nl> return InstallResult : : Success ; <nl> - } else if ( res = = FileSys : : InstallResult : : ErrorAlreadyExists ) { <nl> + } else if ( res = = FileSys : : InstallResult : : OverwriteExisting ) { <nl> return InstallResult : : Overwrite ; <nl> } else { <nl> return InstallResult : : Failure ; <nl>
Use proper install result when overwriting files
yuzu-emu/yuzu
1bbc61f5f1f65478727fbe6351240331d77f104d
2020-07-15T17:27:04Z
mmm a / src / base / hashmap . h <nl> ppp b / src / base / hashmap . h <nl> class TemplateHashMapImpl { <nl> / / If entries are inserted during iteration , the effect of <nl> / / calling Next ( ) is undefined . <nl> Entry * Start ( ) const ; <nl> - Entry * Next ( Entry * p ) const ; <nl> + Entry * Next ( Entry * entry ) const ; <nl> <nl> / / Some match functions defined for convenience . <nl> / / TODO ( leszeks ) : This isn ' t really matching pointers , so the name doesn ' t <nl> class TemplateHashMapImpl { <nl> <nl> Entry * map_end ( ) const { return map_ + capacity_ ; } <nl> Entry * Probe ( const Key & key , uint32_t hash ) const ; <nl> + Entry * FillEmptyEntry ( Entry * entry , const Key & key , const Value & value , <nl> + uint32_t hash ) ; <nl> void Initialize ( uint32_t capacity ) ; <nl> void Resize ( ) ; <nl> } ; <nl> template < typename Key , typename Value , class AllocationPolicy > <nl> typename TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Entry * <nl> TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Lookup ( const Key & key , <nl> uint32_t hash ) const { <nl> - Entry * p = Probe ( key , hash ) ; <nl> - return p - > exists ( ) ? p : nullptr ; <nl> + Entry * entry = Probe ( key , hash ) ; <nl> + return entry - > exists ( ) ? entry : nullptr ; <nl> } <nl> <nl> template < typename Key , typename Value , class AllocationPolicy > <nl> typename TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Entry * <nl> TemplateHashMapImpl < Key , Value , AllocationPolicy > : : LookupOrInsert ( <nl> const Key & key , uint32_t hash ) { <nl> / / Find a matching entry . <nl> - Entry * p = Probe ( key , hash ) ; <nl> - if ( p - > exists ( ) ) { <nl> - return p ; <nl> + Entry * entry = Probe ( key , hash ) ; <nl> + if ( entry - > exists ( ) ) { <nl> + return entry ; <nl> } <nl> <nl> - return InsertNew ( key , hash ) ; <nl> + return FillEmptyEntry ( entry , key , Value ( ) , hash ) ; <nl> } <nl> <nl> template < typename Key , typename Value , class AllocationPolicy > <nl> typename TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Entry * <nl> TemplateHashMapImpl < Key , Value , AllocationPolicy > : : InsertNew ( const Key & key , <nl> uint32_t hash ) { <nl> - / / Find a matching entry . <nl> - Entry * p = Probe ( key , hash ) ; <nl> - DCHECK ( ! p - > exists ( ) ) ; <nl> - <nl> - / / No entry found ; construct one in - place in the empty slot using placement <nl> - / / new . <nl> - new ( p ) Entry ( key , Value ( ) , hash ) ; <nl> - occupancy_ + + ; <nl> - <nl> - / / Grow the map if we reached > = 80 % occupancy . <nl> - if ( occupancy_ + occupancy_ / 4 > = capacity_ ) { <nl> - Resize ( ) ; <nl> - p = Probe ( key , hash ) ; <nl> - } <nl> - <nl> - return p ; <nl> + Entry * entry = Probe ( key , hash ) ; <nl> + return FillEmptyEntry ( entry , key , Value ( ) , hash ) ; <nl> } <nl> <nl> template < typename Key , typename Value , class AllocationPolicy > <nl> template < typename Key , typename Value , class AllocationPolicy > <nl> void TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Clear ( ) { <nl> / / Mark all entries as empty . <nl> const Entry * end = map_end ( ) ; <nl> - for ( Entry * p = map_ ; p < end ; p + + ) { <nl> - p - > clear ( ) ; <nl> + for ( Entry * entry = map_ ; entry < end ; entry + + ) { <nl> + entry - > clear ( ) ; <nl> } <nl> occupancy_ = 0 ; <nl> } <nl> TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Start ( ) const { <nl> <nl> template < typename Key , typename Value , class AllocationPolicy > <nl> typename TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Entry * <nl> - TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Next ( Entry * p ) const { <nl> + TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Next ( Entry * entry ) const { <nl> const Entry * end = map_end ( ) ; <nl> - DCHECK ( map_ - 1 < = p & & p < end ) ; <nl> - for ( p + + ; p < end ; p + + ) { <nl> - if ( p - > exists ( ) ) { <nl> - return p ; <nl> + DCHECK ( map_ - 1 < = entry & & entry < end ) ; <nl> + for ( entry + + ; entry < end ; entry + + ) { <nl> + if ( entry - > exists ( ) ) { <nl> + return entry ; <nl> } <nl> } <nl> return nullptr ; <nl> typename TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Entry * <nl> TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Probe ( const Key & key , <nl> uint32_t hash ) const { <nl> DCHECK ( base : : bits : : IsPowerOfTwo32 ( capacity_ ) ) ; <nl> - Entry * p = map_ + ( hash & ( capacity_ - 1 ) ) ; <nl> + Entry * entry = map_ + ( hash & ( capacity_ - 1 ) ) ; <nl> const Entry * end = map_end ( ) ; <nl> - DCHECK ( map_ < = p & & p < end ) ; <nl> + DCHECK ( map_ < = entry & & entry < end ) ; <nl> <nl> DCHECK ( occupancy_ < capacity_ ) ; / / Guarantees loop termination . <nl> - while ( p - > exists ( ) & & ( hash ! = p - > hash | | ! match_ ( key , p - > key ) ) ) { <nl> - p + + ; <nl> - if ( p > = end ) { <nl> - p = map_ ; <nl> + while ( entry - > exists ( ) & & ( hash ! = entry - > hash | | ! match_ ( key , entry - > key ) ) ) { <nl> + entry + + ; <nl> + if ( entry > = end ) { <nl> + entry = map_ ; <nl> } <nl> } <nl> <nl> - return p ; <nl> + return entry ; <nl> + } <nl> + <nl> + template < typename Key , typename Value , class AllocationPolicy > <nl> + typename TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Entry * <nl> + TemplateHashMapImpl < Key , Value , AllocationPolicy > : : FillEmptyEntry ( <nl> + Entry * entry , const Key & key , const Value & value , uint32_t hash ) { <nl> + DCHECK ( ! entry - > exists ( ) ) ; <nl> + <nl> + new ( entry ) Entry ( key , value , hash ) ; <nl> + occupancy_ + + ; <nl> + <nl> + / / Grow the map if we reached > = 80 % occupancy . <nl> + if ( occupancy_ + occupancy_ / 4 > = capacity_ ) { <nl> + Resize ( ) ; <nl> + entry = Probe ( key , hash ) ; <nl> + } <nl> + <nl> + return entry ; <nl> } <nl> <nl> template < typename Key , typename Value , class AllocationPolicy > <nl> void TemplateHashMapImpl < Key , Value , AllocationPolicy > : : Resize ( ) { <nl> Initialize ( capacity_ * 2 ) ; <nl> <nl> / / Rehash all current entries . <nl> - for ( Entry * p = map ; n > 0 ; p + + ) { <nl> - if ( p - > exists ( ) ) { <nl> - Entry * entry = LookupOrInsert ( p - > key , p - > hash ) ; <nl> - entry - > value = p - > value ; <nl> + for ( Entry * entry = map ; n > 0 ; entry + + ) { <nl> + if ( entry - > exists ( ) ) { <nl> + Entry * new_entry = Probe ( entry - > key , entry - > hash ) ; <nl> + new_entry = <nl> + FillEmptyEntry ( new_entry , entry - > key , entry - > value , entry - > hash ) ; <nl> n - - ; <nl> } <nl> } <nl>
[ base ] Decrease probing in hashmap
v8/v8
bedde181fdd7b444509eab7f382e9ed2740546ec
2016-09-20T11:30:51Z
mmm a / cmake / ConfigGen . cmake <nl> ppp b / cmake / ConfigGen . cmake <nl> function ( caffe_get_current_includes includes_variable ) <nl> list ( FIND current_includes $ { PROJECT_BINARY_DIR } __index ) <nl> list ( REMOVE_AT current_includes $ { __index } ) <nl> <nl> + # removing numpy includes ( since not required for client libs ) <nl> + set ( __toremove " " ) <nl> + foreach ( __i $ { current_includes } ) <nl> + if ( $ { __i } MATCHES " python " ) <nl> + list ( APPEND __toremove $ { __i } ) <nl> + endif ( ) <nl> + endforeach ( ) <nl> + if ( __toremove ) <nl> + list ( REMOVE_ITEM current_includes $ { __toremove } ) <nl> + endif ( ) <nl> + <nl> caffe_list_unique ( current_includes ) <nl> set ( $ { includes_variable } $ { current_includes } PARENT_SCOPE ) <nl> endfunction ( ) <nl>
Merge pull request from Nerei / feature / minor_fix_in_cmake_config_generation
BVLC/caffe
ec5a8f679c171e4727178c0bdeec86797ab2f4ca
2015-05-30T01:10:18Z
mmm a / src / capi / TuriCreate . h <nl> ppp b / src / capi / TuriCreate . h <nl> typedef enum { <nl> / / Sizes ( defaults to medium ) <nl> tc_plot_size_small = 0x01 , <nl> tc_plot_size_medium = 0x02 , <nl> + tc_plot_size_large = 0x03 , <nl> <nl> / / Color variations <nl> / / default could be light / dark depending on OS settings <nl> mmm a / src / unity / lib / visualization / plot . cpp <nl> ppp b / src / unity / lib / visualization / plot . cpp <nl> namespace turi { <nl> labelPadding = " 4 " ; <nl> titleFontSize = " 13 " ; <nl> titleOffset = " 16 " ; <nl> + } else if ( size_variation = = tc_plot_size_large ) { <nl> + / / Large size is 960x840 <nl> + width = " 960 " ; <nl> + height = " 840 " ; <nl> + axisTitleFontSize = " 22 " ; <nl> + axisTitleFontWeight = escape_string ( " bold " ) ; <nl> + axisTitlePadding = " 18 " ; <nl> + labelFontSize = " 18 " ; <nl> + labelPadding = " 18 " ; <nl> + titleFontSize = " 26 " ; <nl> + titleFontWeight = escape_string ( " bold " ) ; <nl> + titleOffset = " 30 " ; <nl> } <nl> <nl> return format ( ret , { <nl>
Add large plot size to C API ( )
apple/turicreate
23ed99696666b6837f1761bc917e9677a0f5644c
2019-01-28T04:34:35Z
mmm a / test / mjsunit / mjsunit . status <nl> ppp b / test / mjsunit / mjsunit . status <nl> <nl> ' regress / regress - crbug - 119800 ' : [ FAIL ] , <nl> ' regress / regress - crbug - 467180 ' : [ FAIL ] , <nl> ' regress / regress - opt - after - debug - deopt ' : [ FAIL ] , <nl> + ' regress / regress - crbug - 568477 - 2 ' : [ FAIL ] , <nl> <nl> # TODO ( rmcilroy , 4765 ) : assertion failures in LiveEdit tests . <nl> ' debug - liveedit - restart - frame ' : [ FAIL ] , <nl> ' debug - liveedit - literals ' : [ FAIL ] , <nl> ' debug - liveedit - 3 ' : [ FAIL ] , <nl> ' debug - liveedit - 1 ' : [ FAIL ] , <nl> + ' debug - liveedit - 2 ' : [ FAIL ] , <nl> ' debug - liveedit - patch - positions - replace ' : [ FAIL ] , <nl> ' debug - liveedit - patch - positions ' : [ FAIL ] , <nl> ' debug - liveedit - stepin ' : [ FAIL ] , <nl> <nl> ' es6 / debug - liveedit - new - target - 2 ' : [ FAIL ] , <nl> ' es6 / debug - liveedit - new - target - 3 ' : [ FAIL ] , <nl> <nl> + # TODO ( yangguo / rmcilroy , 4690 ) : Related to Debugger . Goes into a loop <nl> + # in function : Debug : : FindSharedFunctionInfoInScript and times out . <nl> + ' regress / regress - crbug - 517592 ' : [ SKIP ] , <nl> + ' regress / regress - 1853 ' : [ SKIP ] , <nl> + ' regress / regress - crbug - 424142 ' : [ SKIP ] , <nl> + <nl> # TODO ( rmcilroy , 4681 ) : Requires support for generators . <nl> ' messages ' : [ FAIL ] , <nl> ' es6 / array - from ' : [ FAIL ] , <nl> <nl> <nl> # TODO ( mythria , 4764 ) : lack of osr support . <nl> ' regress / regress - 2618 ' : [ FAIL ] , <nl> + # TODO ( mythria , 4764 ) : lack of osr support . The tests waits in a loop <nl> + # till it is optimized . So test timeouts . <nl> + ' array - literal - transitions ' : [ SKIP ] , <nl> <nl> - # TODO ( rmcilroy , 4680 ) : Test assert failures . <nl> - ' debug - liveedit - 2 ' : [ FAIL ] , <nl> + # TODO ( mythria , 4680 ) : Relate to GC and ignition holding references to <nl> + # objects . <nl> ' es6 / mirror - collections ' : [ FAIL ] , <nl> - ' es6 / regress / regress - 468661 ' : [ FAIL ] , <nl> + <nl> + # TODO ( mythria , 4680 ) : line numbers in eval test . Coloumn number is <nl> + # incorrect . <nl> ' regress / regress - crbug - 109362 ' : [ FAIL ] , <nl> - ' regress / regress - crbug - 568477 - 2 ' : [ FAIL ] , <nl> <nl> - # TODO ( rmcilroy , 4680 ) : Test timeouts . <nl> - ' array - literal - transitions ' : [ SKIP ] , <nl> - ' regress / regress - crbug - 517592 ' : [ SKIP ] , <nl> - ' regress / regress - crbug - 568477 - 4 ' : [ SKIP ] , <nl> - ' regress / regress - crbug - 409614 ' : [ SKIP ] , <nl> - ' regress / regress - crbug - 42414 ' : [ SKIP ] , <nl> - ' regress / regress - 1853 ' : [ SKIP ] , <nl> - ' regress / regress - crbug - 424142 ' : [ SKIP ] , <nl> + # TODO ( mythria , 4680 ) : possibly problem with line numbers . <nl> + ' es6 / regress / regress - 468661 ' : [ FAIL ] , <nl> <nl> # with statements no longer always have a block as their body <nl> ' regress / regress - 95485 ' : [ SKIP ] , <nl> } ] , # ignition = = True <nl> <nl> [ ' ignition = = True and arch = = arm64 ' , { <nl> - # TODO ( rmcilroy , 4680 ) : Fails on Arm64 due to expecting to take less than 3 <nl> - # seconds . <nl> - ' regress / regress - 165637 ' : [ FAIL ] , <nl> - } ] , # ignition = = True and arch = = arm64 <nl> - <nl> - [ ' ignition = = True and ( arch = = arm or arch = = arm64 ) ' , { <nl> - # TODO ( rmcilroy , 4680 ) : Arm / Arm64 specific timeouts . <nl> + # TODO ( rmcilroy , 4680 ) : Arm64 specific timeouts . <nl> ' asm / construct - double ' : [ SKIP ] , <nl> - ' compiler / osr - nested ' : [ SKIP ] , <nl> ' compiler / osr - one ' : [ SKIP ] , <nl> ' compiler / osr - two ' : [ SKIP ] , <nl> + } ] , # ignition = = True and arch = = arm64 <nl> + <nl> + [ ' ignition = = True and arch = = arm ' , { <nl> + # TODO ( rmcilroy , 4680 ) : Arm specific timeouts . <nl> + ' compiler / osr - one ' : [ PASS , [ ' mode = = debug ' , SKIP ] ] , <nl> + ' compiler / osr - two ' : [ PASS , [ ' mode = = debug ' , SKIP ] ] , <nl> ' regress / regress - 1257 ' : [ SKIP ] , <nl> - ' regress / regress - 165637 ' : [ SKIP ] , <nl> - ' regress / regress - 2185 ' : [ SKIP ] , <nl> - ' regress / regress - 91008 ' : [ SKIP ] , <nl> - ' unicodelctest ' : [ SKIP ] , <nl> - ' unicodelctest - no - optimization ' : [ SKIP ] , <nl> } ] , # ignition = = True and ( arch = = arm or arch = = arm64 ) <nl> <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl>
[ Interpreter ] Updated mjsunit . status
v8/v8
b455e2b2a0df51c3d91372293c3bb5f77f01b467
2016-03-07T15:13:03Z
new file mode 100644 <nl> index 00000000000 . . 390cb3183c4 <nl> mmm / dev / null <nl> ppp b / docs / en / getting_started / index . md <nl> <nl> + # Getting Started <nl> + <nl> + If you are new to ClickHouse and want to get a hands - on feeling of it ' s performance , first of all you need to go through the [ installation process ] ( install . md ) . <nl> + <nl> + After that you can choose one of the following options : <nl> + <nl> + * [ Go through detailed tutorial ] ( tutorial . md ) <nl> + * [ Experiment with example datasets ] ( example_datasets / ontime . md ) <nl> + <nl> + [ Original article ] ( https : / / clickhouse . yandex / docs / en / getting_started / ) < ! - - hide - - > <nl>
add . . / en / getting_started / index . md
ClickHouse/ClickHouse
9e8e7709f6d91eb752dec57f79cc2eabbcfbb534
2019-08-23T15:29:58Z
mmm a / src / ruby / pb / test / client . rb <nl> ppp b / src / ruby / pb / test / client . rb <nl> def ssl_creds ( use_test_ca ) <nl> def create_stub ( opts ) <nl> address = " # { opts . host } : # { opts . port } " <nl> if opts . secure <nl> + creds = ssl_creds ( opts . use_test_ca ) <nl> stub_opts = { <nl> - : creds = > ssl_creds ( opts . use_test_ca ) , <nl> GRPC : : Core : : Channel : : SSL_TARGET = > opts . host_override <nl> } <nl> <nl> def create_stub ( opts ) <nl> unless opts . oauth_scope . nil ? <nl> auth_creds = Google : : Auth . get_application_default ( opts . oauth_scope ) <nl> call_creds = GRPC : : Core : : CallCredentials . new ( auth_creds . updater_proc ) <nl> - stub_opts [ : creds ] = stub_opts [ : creds ] . compose call_creds <nl> + creds = creds . compose call_creds <nl> end <nl> end <nl> <nl> def create_stub ( opts ) <nl> <nl> # use a metadata update proc that just adds the auth token . <nl> call_creds = GRPC : : Core : : CallCredentials . new ( proc { | md | md . merge ( kw ) } ) <nl> - stub_opts [ : creds ] = stub_opts [ : creds ] . compose call_creds <nl> + creds = creds . compose call_creds <nl> end <nl> <nl> if opts . test_case = = ' jwt_token_creds ' # don ' t use a scope <nl> auth_creds = Google : : Auth . get_application_default <nl> call_creds = GRPC : : Core : : CallCredentials . new ( auth_creds . updater_proc ) <nl> - stub_opts [ : creds ] = stub_opts [ : creds ] . compose call_creds <nl> + creds = creds . compose call_creds <nl> end <nl> <nl> GRPC . logger . info ( " . . . connecting securely to # { address } " ) <nl> - Grpc : : Testing : : TestService : : Stub . new ( address , * * stub_opts ) <nl> + Grpc : : Testing : : TestService : : Stub . new ( address , creds , * * stub_opts ) <nl> else <nl> GRPC . logger . info ( " . . . connecting insecurely to # { address } " ) <nl> - Grpc : : Testing : : TestService : : Stub . new ( address ) <nl> + Grpc : : Testing : : TestService : : Stub . new ( address , : this_channel_is_insecure ) <nl> end <nl> end <nl> <nl>
Fixed stub construction in interop client
grpc/grpc
d24424ff666e911473df3767d1eb45058c19423f
2015-12-16T22:01:26Z
mmm a / folly / detail / MemoryIdler . h <nl> ppp b / folly / detail / MemoryIdler . h <nl> struct MemoryIdler { <nl> / / / avoid synchronizing their flushes . <nl> static AtomicStruct < std : : chrono : : steady_clock : : duration > defaultIdleTimeout ; <nl> <nl> + / / / Selects a timeout pseudo - randomly chosen to be between <nl> + / / / idleTimeout and idleTimeout * ( 1 + timeoutVariationFraction ) , to <nl> + / / / smooth out the behavior in a bursty system <nl> + template < typename Clock = std : : chrono : : steady_clock > <nl> + static typename Clock : : duration getVariationTimeout ( <nl> + typename Clock : : duration idleTimeout <nl> + = defaultIdleTimeout . load ( std : : memory_order_acquire ) , <nl> + float timeoutVariationFrac = 0 . 5 ) { <nl> + if ( idleTimeout . count ( ) > 0 & & timeoutVariationFrac > 0 ) { <nl> + / / hash the pthread_t and the time to get the adjustment . <nl> + / / Standard hash func isn ' t very good , so bit mix the result <nl> + auto pr = std : : make_pair ( pthread_self ( ) , <nl> + Clock : : now ( ) . time_since_epoch ( ) . count ( ) ) ; <nl> + std : : hash < decltype ( pr ) > hash_fn ; <nl> + uint64_t h = folly : : hash : : twang_mix64 ( hash_fn ( pr ) ) ; <nl> + <nl> + / / multiplying the duration by a floating point doesn ' t work , grr . . <nl> + auto extraFrac = <nl> + timeoutVariationFrac / std : : numeric_limits < uint64_t > : : max ( ) * h ; <nl> + uint64_t tics = idleTimeout . count ( ) * ( 1 + extraFrac ) ; <nl> + idleTimeout = typename Clock : : duration ( tics ) ; <nl> + } <nl> + <nl> + return idleTimeout ; <nl> + } <nl> <nl> / / / Equivalent to fut . futexWait ( expected , waitMask ) , but calls <nl> / / / flushLocalMallocCaches ( ) and unmapUnusedStack ( stackToRetain ) <nl> struct MemoryIdler { <nl> return fut . futexWait ( expected , waitMask ) ; <nl> } <nl> <nl> + idleTimeout = getVariationTimeout ( idleTimeout , timeoutVariationFrac ) ; <nl> if ( idleTimeout . count ( ) > 0 ) { <nl> - auto begin = Clock : : now ( ) ; <nl> - <nl> - if ( timeoutVariationFrac > 0 ) { <nl> - / / hash the pthread_t and the time to get the adjustment . <nl> - / / Standard hash func isn ' t very good , so bit mix the result <nl> - auto pr = std : : make_pair ( pthread_self ( ) , <nl> - begin . time_since_epoch ( ) . count ( ) ) ; <nl> - std : : hash < decltype ( pr ) > hash_fn ; <nl> - uint64_t h = folly : : hash : : twang_mix64 ( hash_fn ( pr ) ) ; <nl> - <nl> - / / multiplying the duration by a floating point doesn ' t work , grr . . <nl> - auto extraFrac = <nl> - timeoutVariationFrac / std : : numeric_limits < uint64_t > : : max ( ) * h ; <nl> - uint64_t tics = idleTimeout . count ( ) * ( 1 + extraFrac ) ; <nl> - idleTimeout = typename Clock : : duration ( tics ) ; <nl> - } <nl> - <nl> while ( true ) { <nl> - auto rv = fut . futexWaitUntil ( expected , begin + idleTimeout , waitMask ) ; <nl> + auto rv = fut . futexWaitUntil ( <nl> + expected , Clock : : now ( ) + idleTimeout , waitMask ) ; <nl> if ( rv = = FutexResult : : TIMEDOUT ) { <nl> / / timeout is over <nl> break ; <nl> mmm a / folly / experimental / wangle / concurrent / IOThreadPoolExecutor . cpp <nl> ppp b / folly / experimental / wangle / concurrent / IOThreadPoolExecutor . cpp <nl> <nl> # include < glog / logging . h > <nl> # include < folly / io / async / EventBaseManager . h > <nl> <nl> + # include < folly / detail / MemoryIdler . h > <nl> + <nl> namespace folly { namespace wangle { <nl> <nl> + using folly : : detail : : MemoryIdler ; <nl> + <nl> + / * Class that will free jemalloc caches and madvise the stack away <nl> + * if the event loop is unused for some period of time <nl> + * / <nl> + class MemoryIdlerTimeout <nl> + : public AsyncTimeout , public EventBase : : LoopCallback { <nl> + public : <nl> + explicit MemoryIdlerTimeout ( EventBase * b ) : AsyncTimeout ( b ) , base_ ( b ) { } <nl> + <nl> + virtual void timeoutExpired ( ) noexcept { <nl> + idled = true ; <nl> + } <nl> + <nl> + virtual void runLoopCallback ( ) noexcept { <nl> + if ( idled ) { <nl> + MemoryIdler : : flushLocalMallocCaches ( ) ; <nl> + MemoryIdler : : unmapUnusedStack ( MemoryIdler : : kDefaultStackToRetain ) ; <nl> + <nl> + idled = false ; <nl> + } else { <nl> + std : : chrono : : steady_clock : : duration idleTimeout = <nl> + MemoryIdler : : defaultIdleTimeout . load ( <nl> + std : : memory_order_acquire ) ; <nl> + <nl> + idleTimeout = MemoryIdler : : getVariationTimeout ( idleTimeout ) ; <nl> + <nl> + scheduleTimeout ( std : : chrono : : duration_cast < std : : chrono : : milliseconds > ( <nl> + idleTimeout ) . count ( ) ) ; <nl> + } <nl> + <nl> + / / reschedule this callback for the next event loop . <nl> + base_ - > runBeforeLoop ( this ) ; <nl> + } <nl> + private : <nl> + EventBase * base_ ; <nl> + bool idled { false } ; <nl> + } ; <nl> + <nl> IOThreadPoolExecutor : : IOThreadPoolExecutor ( <nl> size_t numThreads , <nl> std : : shared_ptr < ThreadFactory > threadFactory ) <nl> void IOThreadPoolExecutor : : threadRun ( ThreadPtr thread ) { <nl> const auto ioThread = std : : static_pointer_cast < IOThread > ( thread ) ; <nl> ioThread - > eventBase = <nl> folly : : EventBaseManager : : get ( ) - > getEventBase ( ) ; <nl> + <nl> + auto idler = new MemoryIdlerTimeout ( ioThread - > eventBase ) ; <nl> + ioThread - > eventBase - > runBeforeLoop ( idler ) ; <nl> + <nl> thread - > startupBaton . post ( ) ; <nl> while ( ioThread - > shouldRun ) { <nl> ioThread - > eventBase - > loopForever ( ) ; <nl> mmm a / folly / io / async / EventBase . cpp <nl> ppp b / folly / io / async / EventBase . cpp <nl> EventBase : : ~ EventBase ( ) { <nl> callback - > runLoopCallback ( ) ; <nl> } <nl> <nl> - / / Delete any unfired CobTimeout objects , so that we don ' t leak memory <nl> + / / Delete any unfired callback objects , so that we don ' t leak memory <nl> / / ( Note that we don ' t fire them . The caller is responsible for cleaning up <nl> / / its own data structures if it destroys the EventBase with unfired events <nl> / / remaining . ) <nl> EventBase : : ~ EventBase ( ) { <nl> delete timeout ; <nl> } <nl> <nl> + while ( ! noWaitLoopCallbacks_ . empty ( ) ) { <nl> + delete & noWaitLoopCallbacks_ . front ( ) ; <nl> + } <nl> + <nl> ( void ) runLoopCallbacks ( false ) ; <nl> <nl> / / Stop consumer before deleting NotificationQueue <nl> bool EventBase : : loopBody ( int flags ) { <nl> / / nobody can add loop callbacks from within this thread if <nl> / / we don ' t have to handle anything to start with . . . <nl> if ( blocking & & loopCallbacks_ . empty ( ) ) { <nl> + LoopCallbackList callbacks ; <nl> + callbacks . swap ( noWaitLoopCallbacks_ ) ; <nl> + <nl> + while ( ! callbacks . empty ( ) ) { <nl> + auto * item = & callbacks . front ( ) ; <nl> + callbacks . pop_front ( ) ; <nl> + item - > runLoopCallback ( ) ; <nl> + } <nl> + <nl> res = event_base_loop ( evb_ , EVLOOP_ONCE ) ; <nl> } else { <nl> res = event_base_loop ( evb_ , EVLOOP_ONCE | EVLOOP_NONBLOCK ) ; <nl> } <nl> + <nl> ranLoopCallbacks = runLoopCallbacks ( ) ; <nl> <nl> int64_t busy = std : : chrono : : duration_cast < std : : chrono : : microseconds > ( <nl> void EventBase : : runOnDestruction ( LoopCallback * callback ) { <nl> onDestructionCallbacks_ . push_back ( * callback ) ; <nl> } <nl> <nl> + void EventBase : : runBeforeLoop ( LoopCallback * callback ) { <nl> + DCHECK ( isInEventBaseThread ( ) ) ; <nl> + callback - > cancelLoopCallback ( ) ; <nl> + noWaitLoopCallbacks_ . push_back ( * callback ) ; <nl> + } <nl> + <nl> bool EventBase : : runInEventBaseThread ( void ( * fn ) ( void * ) , void * arg ) { <nl> / / Send the message . <nl> / / It will be received by the FunctionRunner in the EventBase ' s thread . <nl> mmm a / folly / io / async / EventBase . h <nl> ppp b / folly / io / async / EventBase . h <nl> class EventBase : private boost : : noncopyable , public TimeoutManager { <nl> * / <nl> void runOnDestruction ( LoopCallback * callback ) ; <nl> <nl> + void runBeforeLoop ( LoopCallback * callback ) ; <nl> + <nl> / * * <nl> * Run the specified function in the EventBase ' s thread . <nl> * <nl> class EventBase : private boost : : noncopyable , public TimeoutManager { <nl> CobTimeout : : List pendingCobTimeouts_ ; <nl> <nl> LoopCallbackList loopCallbacks_ ; <nl> + LoopCallbackList noWaitLoopCallbacks_ ; <nl> LoopCallbackList onDestructionCallbacks_ ; <nl> <nl> / / This will be null most of the time , but point to currentCallbacks <nl>
Add MemoryIdler suppot to IOThreadPoolExecutor
facebook/folly
4ebfdff303924da5636e512ef7268612cba7c803
2014-10-29T23:06:51Z
mmm a / 3rdParty / velocypack / include / velocypack / Value . h <nl> ppp b / 3rdParty / velocypack / include / velocypack / Value . h <nl> <nl> # include < string > <nl> <nl> # include " velocypack / velocypack - common . h " <nl> + # include " velocypack / Exception . h " <nl> # include " velocypack / ValueType . h " <nl> <nl> namespace arangodb { <nl>
updated vpack library
arangodb/arangodb
6d8d7c9a4c901579e9fab4c0b4733aa77e337fcc
2015-11-24T12:20:47Z
mmm a / modules / prediction / common / prediction_gflags . cc <nl> ppp b / modules / prediction / common / prediction_gflags . cc <nl> DEFINE_string ( torch_vehicle_junction_mlp_file , <nl> DEFINE_string ( torch_vehicle_junction_map_file , <nl> " / apollo / modules / prediction / data / junction_map_vehicle_model . pt " , <nl> " Vehicle junction map model file " ) ; <nl> + DEFINE_string ( torch_vehicle_semantic_lstm_file , <nl> + " / apollo / modules / prediction / data / semantic_lstm_vehicle_model . pt " , <nl> + " Vehicle semantic lstm model file " ) ; <nl> DEFINE_string ( torch_vehicle_cruise_go_file , <nl> " / apollo / modules / prediction / data / cruise_go_vehicle_model . pt " , <nl> " Vehicle cruise go model file " ) ; <nl> mmm a / modules / prediction / common / prediction_gflags . h <nl> ppp b / modules / prediction / common / prediction_gflags . h <nl> DECLARE_double ( still_speed ) ; <nl> DECLARE_string ( evaluator_vehicle_mlp_file ) ; <nl> DECLARE_string ( torch_vehicle_junction_mlp_file ) ; <nl> DECLARE_string ( torch_vehicle_junction_map_file ) ; <nl> + DECLARE_string ( torch_vehicle_semantic_lstm_file ) ; <nl> DECLARE_string ( torch_vehicle_cruise_go_file ) ; <nl> DECLARE_string ( torch_vehicle_cruise_cutin_file ) ; <nl> DECLARE_string ( torch_vehicle_lane_scanning_file ) ; <nl> new file mode 100644 <nl> index 00000000000 . . 560e411c51b <nl> Binary files / dev / null and b / modules / prediction / data / semantic_lstm_vehicle_model . pt differ <nl> mmm a / modules / prediction / evaluator / vehicle / semantic_lstm_evaluator . cc <nl> ppp b / modules / prediction / evaluator / vehicle / semantic_lstm_evaluator . cc <nl> void SemanticLSTMEvaluator : : LoadModel ( ) { <nl> device_ = torch : : Device ( torch : : kCUDA ) ; <nl> } <nl> torch : : set_num_threads ( 1 ) ; <nl> - / / TODO ( Hongyi ) : change model file name and gflag <nl> torch_model_ = <nl> - torch : : jit : : load ( FLAGS_torch_vehicle_junction_map_file , device_ ) ; <nl> + torch : : jit : : load ( FLAGS_torch_vehicle_semantic_lstm_file , device_ ) ; <nl> } <nl> <nl> } / / namespace prediction <nl>
Prediction : add semantic_lstm_model file
ApolloAuto/apollo
0b640ec6179f184a971a5140b0eab00c7ae833f1
2019-11-05T20:57:28Z
mmm a / taskcluster / tc - all - vars . sh <nl> ppp b / taskcluster / tc - all - vars . sh <nl> SUPPORTED_PYTHON_VERSIONS = $ { SUPPORTED_PYTHON_VERSIONS : - 3 . 5 . 8 : ucs2 3 . 6 . 10 : ucs2 3 . <nl> SUPPORTED_NODEJS_BUILD_VERSIONS = $ { SUPPORTED_NODEJS_BUILD_VERSIONS : - 10 . 0 . 0 11 . 0 . 0 12 . 7 . 0 13 . 0 . 0 14 . 0 . 0 15 . 0 . 0 } <nl> SUPPORTED_NODEJS_TESTS_VERSIONS = $ { SUPPORTED_NODEJS_TESTS_VERSIONS : - 10 . 20 . 1 11 . 15 . 0 12 . 17 . 0 13 . 14 . 0 14 . 3 . 0 15 . 0 . 0 } <nl> <nl> - SUPPORTED_ELECTRONJS_VERSIONS = $ { SUPPORTED_ELECTRONJS_VERSIONS : - 5 . 0 . 13 6 . 0 . 12 6 . 1 . 7 7 . 0 . 1 7 . 1 . 8 8 . 0 . 1 9 . 0 . 1 9 . 1 . 0 9 . 2 . 0 10 . 0 . 0 10 . 1 . 0 } <nl> + SUPPORTED_ELECTRONJS_VERSIONS = $ { SUPPORTED_ELECTRONJS_VERSIONS : - 5 . 0 . 13 6 . 0 . 12 6 . 1 . 7 7 . 0 . 1 7 . 1 . 8 8 . 0 . 1 9 . 0 . 1 9 . 1 . 0 9 . 2 . 0 10 . 0 . 0 10 . 1 . 0 11 . 0 . 0 } <nl> new file mode 100644 <nl> index 000000000 . . f17e47b58 <nl> mmm / dev / null <nl> ppp b / taskcluster / test - electronjs_v11 . 0 - darwin - amd64 - opt . yml <nl> <nl> + build : <nl> + template_file : test - darwin - opt - base . tyml <nl> + dependencies : <nl> + - " darwin - amd64 - cpu - opt " <nl> + - " test - training_16k - linux - amd64 - py36m - opt " <nl> + - " homebrew_tests - darwin - amd64 " <nl> + test_model_task : " test - training_16k - linux - amd64 - py36m - opt " <nl> + system_setup : <nl> + > <nl> + $ { nodejs . brew . prep_12 } <nl> + args : <nl> + tests_cmdline : " $ TASKCLUSTER_TASK_DIR / DeepSpeech / ds / taskcluster / tc - electron - tests . sh 12 . x 11 . 0 . 0 16k " <nl> + metadata : <nl> + name : " DeepSpeech OSX AMD64 CPU ElectronJS v11 . 0 tests " <nl> + description : " Testing DeepSpeech for OSX / AMD64 on ElectronJS v11 . 0 , CPU only , optimized version " <nl> new file mode 100644 <nl> index 000000000 . . c824e3488 <nl> mmm / dev / null <nl> ppp b / taskcluster / test - electronjs_v11 . 0 - win - amd64 - opt . yml <nl> <nl> + build : <nl> + template_file : test - win - opt - base . tyml <nl> + dependencies : <nl> + - " win - amd64 - cpu - opt " <nl> + - " test - training_16k - linux - amd64 - py36m - opt " <nl> + test_model_task : " test - training_16k - linux - amd64 - py36m - opt " <nl> + system_setup : <nl> + > <nl> + $ { system . sox_win } & & $ { nodejs . win . prep_12 } <nl> + args : <nl> + tests_cmdline : " $ { system . homedir . win } / DeepSpeech / ds / taskcluster / tc - electron - tests . sh 12 . x 11 . 0 . 0 16k " <nl> + metadata : <nl> + name : " DeepSpeech Windows AMD64 CPU ElectronJS v11 . 0 tests " <nl> + description : " Testing DeepSpeech for Windows / AMD64 on ElectronJS v11 . 0 , CPU only , optimized version " <nl> new file mode 100644 <nl> index 000000000 . . 89e65ac20 <nl> mmm / dev / null <nl> ppp b / taskcluster / test - electronjs_v11 . 0_16k - linux - amd64 - opt . yml <nl> <nl> + build : <nl> + template_file : test - linux - opt - base . tyml <nl> + docker_image : " ubuntu : 16 . 04 " <nl> + dependencies : <nl> + - " linux - amd64 - cpu - opt " <nl> + - " test - training_16k - linux - amd64 - py36m - opt " <nl> + test_model_task : " test - training_16k - linux - amd64 - py36m - opt " <nl> + system_setup : <nl> + > <nl> + $ { nodejs . packages_xenial . prep_12 } & & $ { nodejs . packages_xenial . apt_pinning } & & apt - get - qq update & & apt - get - qq - y install $ { nodejs . packages_xenial . apt } $ { electronjs . packages_xenial . apt } <nl> + args : <nl> + tests_cmdline : " $ { system . homedir . linux } / DeepSpeech / ds / taskcluster / tc - electron - tests . sh 12 . x 11 . 0 . 0 16k " <nl> + workerType : " $ { docker . dsTests } " <nl> + metadata : <nl> + name : " DeepSpeech Linux AMD64 CPU ElectronJS v11 . 0 tests ( 16kHz ) " <nl> + description : " Testing DeepSpeech for Linux / AMD64 on ElectronJS v11 . 0 , CPU only , optimized version ( 16kHz ) " <nl> new file mode 100644 <nl> index 000000000 . . 23be3b9b6 <nl> mmm / dev / null <nl> ppp b / taskcluster / test - electronjs_v11 . 0_8k - linux - amd64 - opt . yml <nl> <nl> + build : <nl> + template_file : test - linux - opt - base . tyml <nl> + docker_image : " ubuntu : 16 . 04 " <nl> + dependencies : <nl> + - " linux - amd64 - cpu - opt " <nl> + - " test - training_8k - linux - amd64 - py36m - opt " <nl> + test_model_task : " test - training_8k - linux - amd64 - py36m - opt " <nl> + system_setup : <nl> + > <nl> + $ { nodejs . packages_xenial . prep_12 } & & $ { nodejs . packages_xenial . apt_pinning } & & apt - get - qq update & & apt - get - qq - y install $ { nodejs . packages_xenial . apt } $ { electronjs . packages_xenial . apt } <nl> + args : <nl> + tests_cmdline : " $ { system . homedir . linux } / DeepSpeech / ds / taskcluster / tc - electron - tests . sh 12 . x 11 . 0 . 0 8k " <nl> + workerType : " $ { docker . dsTests } " <nl> + metadata : <nl> + name : " DeepSpeech Linux AMD64 CPU ElectronJS v11 . 0 tests ( 8kHz ) " <nl> + description : " Testing DeepSpeech for Linux / AMD64 on ElectronJS v11 . 0 , CPU only , optimized version ( 8kHz ) " <nl> new file mode 100644 <nl> index 000000000 . . cbcf59dda <nl> mmm / dev / null <nl> ppp b / taskcluster / test - electronjs_v11 . 0_multiarchpkg - win - amd64 - opt . yml <nl> <nl> + build : <nl> + template_file : test - win - opt - base . tyml <nl> + dependencies : <nl> + - " node - package - cpu " <nl> + - " test - training_16k - linux - amd64 - py36m - opt " <nl> + test_model_task : " test - training_16k - linux - amd64 - py36m - opt " <nl> + system_setup : <nl> + > <nl> + $ { system . sox_win } & & $ { nodejs . win . prep_12 } <nl> + args : <nl> + tests_cmdline : " $ { system . homedir . win } / DeepSpeech / ds / taskcluster / tc - electron - tests . sh 12 . x 11 . 0 . 0 16k " <nl> + metadata : <nl> + name : " DeepSpeech Windows AMD64 CPU ElectronJS MultiArch Package v11 . 0 tests " <nl> + description : " Testing DeepSpeech for Windows / AMD64 on ElectronJS MultiArch Package v11 . 0 , CPU only , optimized version " <nl> new file mode 100644 <nl> index 000000000 . . bf5640b67 <nl> mmm / dev / null <nl> ppp b / taskcluster / test - electronjs_v11 . 0_multiarchpkg - win - cuda - opt . yml <nl> <nl> + build : <nl> + template_file : test - win - cuda - opt - base . tyml <nl> + dependencies : <nl> + - " node - package - gpu " <nl> + - " test - training_16k - linux - amd64 - py36m - opt " <nl> + test_model_task : " test - training_16k - linux - amd64 - py36m - opt " <nl> + system_setup : <nl> + > <nl> + $ { system . sox_win } & & $ { nodejs . win . prep_12 } <nl> + args : <nl> + tests_cmdline : " $ { system . homedir . win } / DeepSpeech / ds / taskcluster / tc - electron - tests . sh 12 . x 11 . 0 . 0 16k cuda " <nl> + metadata : <nl> + name : " DeepSpeech Windows AMD64 CUDA ElectronJS MultiArch Package v11 . 0 tests " <nl> + description : " Testing DeepSpeech for Windows / AMD64 on ElectronJS MultiArch Package v11 . 0 , CUDA , optimized version " <nl> new file mode 100644 <nl> index 000000000 . . 079e2d3b5 <nl> mmm / dev / null <nl> ppp b / taskcluster / test - electronjs_v11 . 0_multiarchpkg - win - tflite - opt . yml <nl> <nl> + build : <nl> + template_file : test - win - opt - base . tyml <nl> + dependencies : <nl> + - " node - package - tflite " <nl> + - " test - training_16k - linux - amd64 - py36m - opt " <nl> + test_model_task : " test - training_16k - linux - amd64 - py36m - opt " <nl> + system_setup : <nl> + > <nl> + $ { system . sox_win } & & $ { nodejs . win . prep_12 } <nl> + args : <nl> + tests_cmdline : " $ { system . homedir . win } / DeepSpeech / ds / taskcluster / tc - electron_tflite - tests . sh 12 . x 11 . 0 . 0 16k " <nl> + metadata : <nl> + name : " DeepSpeech Windows AMD64 TFLite ElectronJS MultiArch Package v11 . 0 tests " <nl> + description : " Testing DeepSpeech for Windows / AMD64 on ElectronJS MultiArch Package v11 . 0 , TFLite only , optimized version " <nl>
Adding support for ElectronJS v11 . 0
mozilla/DeepSpeech
c0c5e6ade8b78a845fb5ee7cc8e0e48d8cddaa6a
2020-11-26T12:28:57Z
mmm a / include / swift / SIL / SILConstants . h <nl> ppp b / include / swift / SIL / SILConstants . h <nl> class SymbolicValue { <nl> SymbolicValueMemoryObject * <nl> getAddressValue ( SmallVectorImpl < unsigned > & accessPath ) const ; <nl> <nl> + / / / Return just the memory object for an address value . <nl> + SymbolicValueMemoryObject * getAddressValueMemoryObject ( ) const ; <nl> + <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - = = = / / <nl> / / Helpers <nl> <nl> struct SymbolicValueMemoryObject { <nl> static SymbolicValueMemoryObject * create ( Type type , SymbolicValue value , <nl> ASTContext & astContext ) ; <nl> <nl> + / / / Given that this memory object contains an aggregate value like <nl> + / / / { { 1 , 2 } , 3 } , and given an access path like [ 0 , 1 ] , return the indexed <nl> + / / / element , e . g . " 2 " in this case . <nl> + / / / <nl> + / / / Returns uninit memory if the access path points at or into uninit memory . <nl> + / / / <nl> + / / / Precondition : The access path must be valid for this memory object ' s type . <nl> + SymbolicValue getIndexedElement ( ArrayRef < unsigned > accessPath ) ; <nl> + <nl> + / / / Given that this memory object contains an aggregate value like <nl> + / / / { { 1 , 2 } , 3 } , given an access path like [ 0 , 1 ] , and given a new element like <nl> + / / / " 4 " , set the indexed element to the specified scalar , producing { { 1 , 4 } , <nl> + / / / 3 } in this case . <nl> + / / / <nl> + / / / Precondition : The access path must be valid for this memory object ' s type . <nl> + void setIndexedElement ( ArrayRef < unsigned > accessPath , <nl> + SymbolicValue newElement , ASTContext & astCtx ) ; <nl> + <nl> private : <nl> const Type type ; <nl> SymbolicValue value ; <nl> mmm a / lib / SIL / SILConstants . cpp <nl> ppp b / lib / SIL / SILConstants . cpp <nl> SymbolicValue : : getAddressValue ( SmallVectorImpl < unsigned > & accessPath ) const { <nl> return dav - > memoryObject ; <nl> } <nl> <nl> + / / / Return just the memory object for an address value . <nl> + SymbolicValueMemoryObject * SymbolicValue : : getAddressValueMemoryObject ( ) const { <nl> + if ( representationKind = = RK_DirectAddress ) <nl> + return value . directAddress ; <nl> + assert ( representationKind = = RK_DerivedAddress ) ; <nl> + return value . derivedAddress - > memoryObject ; <nl> + } <nl> + <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> / / Higher level code <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> void SymbolicValue : : emitUnknownDiagnosticNotes ( SILLocation fallbackLoc ) { <nl> emittedFirstNote = true ; <nl> } <nl> } <nl> + <nl> + / / / Returns the element of ` aggregate ` specified by the access path . <nl> + / / / <nl> + / / / This is a helper for ` SymbolicValueMemoryObject : : getIndexedElement ` . See <nl> + / / / there for more detailed documentation . <nl> + static SymbolicValue getIndexedElement ( SymbolicValue aggregate , <nl> + ArrayRef < unsigned > accessPath , <nl> + Type type ) { <nl> + / / We ' re done if we ' ve run out of access path . <nl> + if ( accessPath . empty ( ) ) <nl> + return aggregate ; <nl> + <nl> + / / Everything inside uninit memory is uninit memory . <nl> + if ( aggregate . getKind ( ) = = SymbolicValue : : UninitMemory ) <nl> + return SymbolicValue : : getUninitMemory ( ) ; <nl> + <nl> + assert ( aggregate . getKind ( ) = = SymbolicValue : : Aggregate & & <nl> + " the accessPath is invalid for this type " ) ; <nl> + <nl> + unsigned elementNo = accessPath . front ( ) ; <nl> + <nl> + SymbolicValue elt = aggregate . getAggregateValue ( ) [ elementNo ] ; <nl> + Type eltType ; <nl> + if ( auto * decl = type - > getStructOrBoundGenericStruct ( ) ) { <nl> + auto it = decl - > getStoredProperties ( ) . begin ( ) ; <nl> + std : : advance ( it , elementNo ) ; <nl> + eltType = ( * it ) - > getType ( ) ; <nl> + } else if ( auto tuple = type - > getAs < TupleType > ( ) ) { <nl> + assert ( elementNo < tuple - > getNumElements ( ) & & " invalid index " ) ; <nl> + eltType = tuple - > getElement ( elementNo ) . getType ( ) ; <nl> + } else { <nl> + llvm_unreachable ( " the accessPath is invalid for this type " ) ; <nl> + } <nl> + <nl> + return getIndexedElement ( elt , accessPath . drop_front ( ) , eltType ) ; <nl> + } <nl> + <nl> + / / / Given that this memory object contains an aggregate value like <nl> + / / / { { 1 , 2 } , 3 } , and given an access path like [ 0 , 1 ] , return the indexed <nl> + / / / element , e . g . " 2 " in this case . <nl> + / / / <nl> + / / / Returns uninit memory if the access path points at or into uninit memory . <nl> + / / / <nl> + / / / Precondition : The access path must be valid for this memory object ' s type . <nl> + SymbolicValue <nl> + SymbolicValueMemoryObject : : getIndexedElement ( ArrayRef < unsigned > accessPath ) { <nl> + return : : getIndexedElement ( value , accessPath , type ) ; <nl> + } <nl> + <nl> + / / / Returns ` aggregate ` with the element specified by the access path set to <nl> + / / / ` newElement ` . <nl> + / / / <nl> + / / / This is a helper for ` SymbolicValueMemoryObject : : setIndexedElement ` . See <nl> + / / / there for more detailed documentation . <nl> + static SymbolicValue setIndexedElement ( SymbolicValue aggregate , <nl> + ArrayRef < unsigned > accessPath , <nl> + SymbolicValue newElement , Type type , <nl> + ASTContext & astCtx ) { <nl> + / / We ' re done if we ' ve run out of access path . <nl> + if ( accessPath . empty ( ) ) <nl> + return newElement ; <nl> + <nl> + / / If we have an uninit memory , then scalarize it into an aggregate to <nl> + / / continue . This happens when memory objects are initialized piecewise . <nl> + if ( aggregate . getKind ( ) = = SymbolicValue : : UninitMemory ) { <nl> + unsigned numMembers ; <nl> + / / We need to have either a struct or a tuple type . <nl> + if ( auto * decl = type - > getStructOrBoundGenericStruct ( ) ) { <nl> + numMembers = std : : distance ( decl - > getStoredProperties ( ) . begin ( ) , <nl> + decl - > getStoredProperties ( ) . end ( ) ) ; <nl> + } else if ( auto tuple = type - > getAs < TupleType > ( ) ) { <nl> + numMembers = tuple - > getNumElements ( ) ; <nl> + } else { <nl> + llvm_unreachable ( " the accessPath is invalid for this type " ) ; <nl> + } <nl> + <nl> + SmallVector < SymbolicValue , 4 > newElts ( numMembers , <nl> + SymbolicValue : : getUninitMemory ( ) ) ; <nl> + aggregate = SymbolicValue : : getAggregate ( newElts , astCtx ) ; <nl> + } <nl> + <nl> + assert ( aggregate . getKind ( ) = = SymbolicValue : : Aggregate & & <nl> + " the accessPath is invalid for this type " ) ; <nl> + <nl> + unsigned elementNo = accessPath . front ( ) ; <nl> + <nl> + ArrayRef < SymbolicValue > oldElts = aggregate . getAggregateValue ( ) ; <nl> + Type eltType ; <nl> + if ( auto * decl = type - > getStructOrBoundGenericStruct ( ) ) { <nl> + auto it = decl - > getStoredProperties ( ) . begin ( ) ; <nl> + std : : advance ( it , elementNo ) ; <nl> + eltType = ( * it ) - > getType ( ) ; <nl> + } else if ( auto tuple = type - > getAs < TupleType > ( ) ) { <nl> + assert ( elementNo < tuple - > getNumElements ( ) & & " invalid index " ) ; <nl> + eltType = tuple - > getElement ( elementNo ) . getType ( ) ; <nl> + } else { <nl> + llvm_unreachable ( " the accessPath is invalid for this type " ) ; <nl> + } <nl> + <nl> + / / Update the indexed element of the aggregate . <nl> + SmallVector < SymbolicValue , 4 > newElts ( oldElts . begin ( ) , oldElts . end ( ) ) ; <nl> + newElts [ elementNo ] = setIndexedElement ( newElts [ elementNo ] , <nl> + accessPath . drop_front ( ) , newElement , <nl> + eltType , astCtx ) ; <nl> + <nl> + aggregate = SymbolicValue : : getAggregate ( newElts , astCtx ) ; <nl> + <nl> + return aggregate ; <nl> + } <nl> + <nl> + / / / Given that this memory object contains an aggregate value like <nl> + / / / { { 1 , 2 } , 3 } , given an access path like [ 0 , 1 ] , and given a new element like <nl> + / / / " 4 " , set the indexed element to the specified scalar , producing { { 1 , 4 } , <nl> + / / / 3 } in this case . <nl> + / / / <nl> + / / / Precondition : The access path must be valid for this memory object ' s type . <nl> + void SymbolicValueMemoryObject : : setIndexedElement ( <nl> + ArrayRef < unsigned > accessPath , SymbolicValue newElement , <nl> + ASTContext & astCtx ) { <nl> + value = : : setIndexedElement ( value , accessPath , newElement , type , astCtx ) ; <nl> + } <nl> mmm a / lib / SILOptimizer / Utils / ConstExpr . cpp <nl> ppp b / lib / SILOptimizer / Utils / ConstExpr . cpp <nl> <nl> # include " swift / SIL / FormalLinkage . h " <nl> # include " swift / SIL / SILBuilder . h " <nl> # include " swift / SIL / SILConstants . h " <nl> + # include " swift / SILOptimizer / Utils / Devirtualize . h " <nl> # include " swift / Serialization / SerializedSILLoader . h " <nl> # include " llvm / ADT / PointerEmbeddedInt . h " <nl> # include " llvm / Support / TrailingObjects . h " <nl> class ConstExprFunctionState { <nl> / / / substitutionMap specifies a mapping from all of the protocol and type <nl> / / / requirements in the generic signature down to concrete conformances and <nl> / / / concrete types . <nl> - / / / TODO ( constexpr patch ) : I have intentionally included this even though it ' s <nl> - / / / unused , so that I don ' t have to add it back to all the function signatures <nl> - / / / when I start using it . <nl> SubstitutionMap substitutionMap ; <nl> <nl> / / / This keeps track of the number of instructions we ' ve evaluated . If this <nl> class ConstExprFunctionState { <nl> llvm : : Optional < SymbolicValue > computeOpaqueCallResult ( ApplyInst * apply , <nl> SILFunction * callee ) ; <nl> <nl> + SymbolicValue getSingleWriterAddressValue ( SILValue addr ) ; <nl> SymbolicValue getConstAddrAndLoadResult ( SILValue addr ) ; <nl> SymbolicValue loadAddrValue ( SILValue addr , SymbolicValue addrVal ) ; <nl> llvm : : Optional < SymbolicValue > computeFSStore ( SymbolicValue storedCst , <nl> SILValue dest ) ; <nl> + <nl> + private : <nl> + llvm : : Optional < SymbolicValue > <nl> + initializeAddressFromSingleWriter ( SILValue addr ) ; <nl> } ; <nl> } / / end anonymous namespace <nl> <nl> Type ConstExprFunctionState : : substituteGenericParamsAndSimpify ( Type ty ) { <nl> SymbolicValue ConstExprFunctionState : : computeConstantValue ( SILValue value ) { <nl> assert ( ! calculatedValues . count ( value ) ) ; <nl> <nl> + / / If the client is asking for the value of a stack object that hasn ' t been <nl> + / / computed , and if fn is null , then we are in top level code , and the <nl> + / / stack object must be a single store value . Since this is a very different <nl> + / / computation , split it out to its own path . <nl> + if ( ! fn & & value - > getType ( ) . isAddress ( ) & & isa < AllocStackInst > ( value ) ) { <nl> + return getSingleWriterAddressValue ( value ) ; <nl> + } <nl> + <nl> / / If this a trivial constant instruction that we can handle , then fold it <nl> / / immediately . <nl> if ( auto * ili = dyn_cast < IntegerLiteralInst > ( value ) ) <nl> SymbolicValue ConstExprFunctionState : : computeConstantValue ( SILValue value ) { <nl> if ( auto li = dyn_cast < LoadInst > ( value ) ) <nl> return getConstAddrAndLoadResult ( li - > getOperand ( ) ) ; <nl> <nl> + / / Try to resolve a witness method against our known conformances . <nl> + if ( auto * wmi = dyn_cast < WitnessMethodInst > ( value ) ) { <nl> + auto confResult = substitutionMap . lookupConformance ( <nl> + wmi - > getLookupType ( ) , wmi - > getConformance ( ) . getRequirement ( ) ) ; <nl> + if ( ! confResult ) <nl> + return evaluator . getUnknown ( value , UnknownReason : : Default ) ; <nl> + auto conf = confResult . getValue ( ) ; <nl> + auto & module = wmi - > getModule ( ) ; <nl> + <nl> + / / Look up the conformance ' s witness table and the member out of it . <nl> + SILFunction * fn = <nl> + module . lookUpFunctionInWitnessTable ( conf , wmi - > getMember ( ) ) . first ; <nl> + / / If we were able to resolve it , then we can proceed . <nl> + if ( fn ) <nl> + return SymbolicValue : : getFunction ( fn ) ; <nl> + <nl> + LLVM_DEBUG ( llvm : : dbgs ( ) <nl> + < < " ConstExpr Unresolved witness : " < < * value < < " \ n " ) ; <nl> + return evaluator . getUnknown ( value , UnknownReason : : Default ) ; <nl> + } <nl> + <nl> if ( auto * builtin = dyn_cast < BuiltinInst > ( value ) ) <nl> return computeConstantValueBuiltin ( builtin ) ; <nl> <nl> ConstExprFunctionState : : computeCallResult ( ApplyInst * apply ) { <nl> paramConstants . push_back ( argValue ) ; <nl> } <nl> <nl> - / / TODO ( constexpr patch ) : This is currently unused , so we don ' t need to <nl> - / / calculate the correct value . Eventually , include code that calculates the <nl> - / / correct value . <nl> + / / If we reached an external function that hasn ' t been deserialized yet , make <nl> + / / sure to pull it in so we can see its body . If that fails , then we can ' t <nl> + / / analyze the function . <nl> + if ( callee - > isExternalDeclaration ( ) ) { <nl> + callee - > getModule ( ) . loadFunction ( callee ) ; <nl> + if ( callee - > isExternalDeclaration ( ) ) <nl> + return computeOpaqueCallResult ( apply , callee ) ; <nl> + } <nl> + <nl> + / / Compute the substitution map for the callee , which maps from all of its <nl> + / / generic requirements to concrete conformances and concrete types . <nl> SubstitutionMap calleeSubMap ; <nl> <nl> + auto calleeFnType = callee - > getLoweredFunctionType ( ) ; <nl> + assert ( <nl> + ! calleeFnType - > hasSelfParam ( ) | | <nl> + ! calleeFnType - > getSelfInstanceType ( ) - > getClassOrBoundGenericClass ( ) & & <nl> + " class methods are not supported " ) ; <nl> + if ( calleeFnType - > getGenericSignature ( ) ) { <nl> + / / Get the substitution map of the call . This maps from the callee ' s space <nl> + / / into the caller ' s world . Witness methods require additional work to <nl> + / / compute a mapping that is valid for the callee . <nl> + SubstitutionMap callSubMap ; <nl> + <nl> + if ( calleeFnType - > getRepresentation ( ) = = <nl> + SILFunctionType : : Representation : : WitnessMethod ) { <nl> + auto protocol = <nl> + calleeFnType - > getWitnessMethodConformance ( ) . getRequirement ( ) ; <nl> + / / Compute a mapping that maps the Self type of the protocol given by <nl> + / / ' requirement ' to the concrete type available in the substitutionMap . <nl> + auto protoSelfToConcreteType = <nl> + apply - > getSubstitutionMap ( ) . subst ( substitutionMap ) ; <nl> + / / Get a concrete protocol conformance by using the mapping for the <nl> + / / Self type of the requirement . <nl> + auto conf = protoSelfToConcreteType . lookupConformance ( <nl> + protocol - > getSelfInterfaceType ( ) - > getCanonicalType ( ) , protocol ) ; <nl> + if ( ! conf . hasValue ( ) ) <nl> + return evaluator . getUnknown ( ( SILInstruction * ) apply , <nl> + UnknownReason : : Default ) ; <nl> + <nl> + callSubMap = getWitnessMethodSubstitutions ( <nl> + apply - > getModule ( ) , ApplySite ( apply ) , callee , conf . getValue ( ) ) ; <nl> + <nl> + / / / Remark : If we ever start to care about evaluating classes , <nl> + / / / getSubstitutionsForCallee ( ) is the analogous mapping function we <nl> + / / / should use to get correct mapping from caller to callee namespace . <nl> + / / / Ideally , the function must be renamed as <nl> + / / / getClassMethodSubstitutions ( ) . <nl> + } else { <nl> + callSubMap = apply - > getSubstitutionMap ( ) ; <nl> + } <nl> + <nl> + / / The substitution map for the callee is the composition of the callers <nl> + / / substitution map , which is always type / conformance to a concrete type <nl> + / / or conformance , with the mapping introduced by the call itself . This <nl> + / / ensures that the callee ' s substitution map can map from its type <nl> + / / namespace back to concrete types and conformances . <nl> + calleeSubMap = callSubMap . subst ( substitutionMap ) ; <nl> + } <nl> + <nl> / / Now that we have successfully folded all of the parameters , we can evaluate <nl> / / the call . <nl> evaluator . pushCallStack ( apply - > getLoc ( ) . getSourceLoc ( ) ) ; <nl> SymbolicValue ConstExprFunctionState : : getConstantValue ( SILValue value ) { <nl> return result ; <nl> } <nl> <nl> - / / / Given an aggregate value like { { 1 , 2 } , 3 } and an access path like [ 0 , 1 ] , and <nl> - / / / a new element like 4 , return the aggregate value with the indexed element <nl> - / / / replaced with the new element , producing { { 1 , 4 } , 3 } in this case . <nl> - / / / If ` writeOnlyOnce ` is true , and the target aggregate element to update <nl> - / / / already has a constant value , fail on the update . <nl> + / / / This is a helper function for ` getSingleWriterAddressValue ` . Callers should <nl> + / / / use ` getSingleWriterAddressValue ` . <nl> / / / <nl> - / / / This returns true on failure and false on success . <nl> + / / / If ` addr ` has no writing uses , returns None . <nl> / / / <nl> - static bool updateIndexedElement ( SymbolicValue & aggregate , <nl> - ArrayRef < unsigned > indices , <nl> - SymbolicValue newElement , Type type , <nl> - bool writeOnlyOnce , <nl> - ASTContext & astContext ) { <nl> - / / We ' re done if we ' ve run out of indices . <nl> - if ( indices . empty ( ) ) { <nl> - aggregate = newElement ; <nl> - return false ; <nl> - } <nl> + / / / If the following conditions hold : <nl> + / / / * ` addr ` points at uninitialized memory ; <nl> + / / / * there are write ( s ) to ` addr ` that , taken together , set the memory <nl> + / / / exactly once ( e . g . a single " store " to ` addr ` OR multiple " store " s to <nl> + / / / different " tuple_element_addr " s of ` addr ` ) ; and <nl> + / / / * the writes ' value ( s ) can be const - evaluated ; <nl> + / / / Then : initializes the memory at ` addr ` and returns None . <nl> + / / / <nl> + / / / Otherwise , sets the memory at ` addr ` to an unknown SymbolicValue , and <nl> + / / / returns the unknown SymbolicValue . <nl> + / / / <nl> + / / / Additional side effects : In all cases , this function might cache address <nl> + / / / values for ` addr ` and for addresses derived from ` addr ` . <nl> + / / / <nl> + / / / Precondition : An address for ` addr ` , or an address that ` addr ` is derived <nl> + / / / from , must be cached in ` computedValues ` . <nl> + llvm : : Optional < SymbolicValue > <nl> + ConstExprFunctionState : : initializeAddressFromSingleWriter ( SILValue addr ) { <nl> + LLVM_DEBUG ( llvm : : dbgs ( ) < < " ConstExpr : initializeAddressFromSingleWriter " <nl> + < < addr ) ; <nl> <nl> - / / If we have an uninit memory , then scalarize it into an aggregate to <nl> - / / continue . This happens when memory objects are initialized piecewise . <nl> - if ( aggregate . getKind ( ) = = SymbolicValue : : UninitMemory ) { <nl> - unsigned numMembers ; <nl> - / / We need to have either a struct or a tuple type . <nl> - if ( auto * decl = type - > getStructOrBoundGenericStruct ( ) ) { <nl> - numMembers = std : : distance ( decl - > getStoredProperties ( ) . begin ( ) , <nl> - decl - > getStoredProperties ( ) . end ( ) ) ; <nl> - } else if ( auto tuple = type - > getAs < TupleType > ( ) ) { <nl> - numMembers = tuple - > getNumElements ( ) ; <nl> - } else { <nl> - return true ; <nl> + SmallVector < unsigned , 4 > accessPath ; <nl> + auto * memoryObject = getConstantValue ( addr ) . getAddressValue ( accessPath ) ; <nl> + <nl> + / / If we detect instructions that initialize an aggregate piecewise , then we <nl> + / / set this flag , which tells us to verify that the entire aggregate has been <nl> + / / initialized . <nl> + bool mustCheckAggregateInitialized = false ; <nl> + <nl> + / / Sets the pointed - at memory to ` value ` . <nl> + auto setMemoryValue = [ & ] ( SymbolicValue value ) { <nl> + memoryObject - > setIndexedElement ( accessPath , value , <nl> + evaluator . getASTContext ( ) ) ; <nl> + } ; <nl> + <nl> + / / Gets the pointed - at memory value . <nl> + auto getMemoryValue = [ & ] ( ) - > SymbolicValue { <nl> + return memoryObject - > getIndexedElement ( accessPath ) ; <nl> + } ; <nl> + <nl> + / / Does all error - condition side - effects , and returns the appropriate error <nl> + / / result . <nl> + / / Precondition : ` unknown ` must be an unknown SymbolicValue . <nl> + auto error = [ & ] ( SymbolicValue unknown ) - > SymbolicValue { <nl> + assert ( unknown . getKind ( ) = = SymbolicValue : : Unknown ) ; <nl> + setMemoryValue ( unknown ) ; <nl> + return unknown ; <nl> + } ; <nl> + <nl> + / / Checks that the pointed - at aggregate is fully initialized . <nl> + / / Precondition : The pointed - at memory value is uninit memory or an <nl> + / / aggregate . <nl> + auto checkAggregateInitialized = [ & ] ( ) - > bool { <nl> + auto memoryValue = getMemoryValue ( ) ; <nl> + return memoryValue . getKind ( ) ! = SymbolicValue : : UninitMemory & & <nl> + llvm : : all_of ( memoryValue . getAggregateValue ( ) , <nl> + [ ] ( SymbolicValue v ) { return v . isConstant ( ) ; } ) ; <nl> + } ; <nl> + <nl> + / / Okay , check out all of the users of this value looking for semantic stores <nl> + / / into the address . If we find more than one , then this was a var or <nl> + / / something else we can ' t handle . <nl> + / / We must iterate over all uses , to make sure there is a single initializer . <nl> + / / The only permitted early exit is when we know for sure that we have failed . <nl> + for ( auto * use : addr - > getUses ( ) ) { <nl> + auto user = use - > getUser ( ) ; <nl> + <nl> + / / Ignore markers , loads , and other things that aren ' t stores to this stack <nl> + / / value . <nl> + if ( isa < LoadInst > ( user ) | | isa < DeallocStackInst > ( user ) | | <nl> + isa < DestroyAddrInst > ( user ) | | isa < DebugValueAddrInst > ( user ) ) <nl> + continue ; <nl> + <nl> + / / TODO : Allow BeginAccess / EndAccess users . <nl> + <nl> + / / If this is a store * to * the memory , analyze the input value . <nl> + if ( auto * si = dyn_cast < StoreInst > ( user ) ) { <nl> + if ( use - > getOperandNumber ( ) = = 1 ) { <nl> + / / Forbid multiple assignment . <nl> + if ( getMemoryValue ( ) . getKind ( ) ! = SymbolicValue : : UninitMemory ) <nl> + return error ( evaluator . getUnknown ( addr , UnknownReason : : Default ) ) ; <nl> + <nl> + auto result = getConstantValue ( si - > getOperand ( 0 ) ) ; <nl> + if ( ! result . isConstant ( ) ) <nl> + return error ( evaluator . getUnknown ( addr , UnknownReason : : Default ) ) ; <nl> + <nl> + setMemoryValue ( result ) ; <nl> + continue ; <nl> + } <nl> } <nl> <nl> - SmallVector < SymbolicValue , 4 > newElts ( numMembers , <nl> - SymbolicValue : : getUninitMemory ( ) ) ; <nl> - aggregate = SymbolicValue : : getAggregate ( newElts , astContext ) ; <nl> - } <nl> + if ( auto * cai = dyn_cast < CopyAddrInst > ( user ) ) { <nl> + / / If this is a copy_addr * from * the memory , then it is a load , ignore it . <nl> + if ( use - > getOperandNumber ( ) = = 0 ) <nl> + continue ; <nl> <nl> - unsigned elementNo = indices . front ( ) ; <nl> + / / If this is a copy_addr * to * the memory , analyze the input value . <nl> + assert ( use - > getOperandNumber ( ) = = 1 & & " copy_addr has two operands " ) ; <nl> <nl> - / / If we have a non - aggregate then fail . <nl> - if ( aggregate . getKind ( ) ! = SymbolicValue : : Aggregate ) <nl> - return true ; <nl> + / / Forbid multiple assignment . <nl> + if ( getMemoryValue ( ) . getKind ( ) ! = SymbolicValue : : UninitMemory ) <nl> + return error ( evaluator . getUnknown ( addr , UnknownReason : : Default ) ) ; <nl> <nl> - ArrayRef < SymbolicValue > oldElts ; <nl> - Type eltType ; <nl> + auto result = getConstAddrAndLoadResult ( cai - > getOperand ( 0 ) ) ; <nl> + if ( ! result . isConstant ( ) ) <nl> + return error ( evaluator . getUnknown ( addr , UnknownReason : : Default ) ) ; <nl> <nl> - / / We need to have a struct or a tuple type . <nl> - oldElts = aggregate . getAggregateValue ( ) ; <nl> + setMemoryValue ( result ) ; <nl> + continue ; <nl> + } <nl> <nl> - if ( auto * decl = type - > getStructOrBoundGenericStruct ( ) ) { <nl> - auto it = decl - > getStoredProperties ( ) . begin ( ) ; <nl> - std : : advance ( it , elementNo ) ; <nl> - eltType = ( * it ) - > getType ( ) ; <nl> - } else if ( auto tuple = type - > getAs < TupleType > ( ) ) { <nl> - assert ( elementNo < tuple - > getNumElements ( ) & & " invalid index " ) ; <nl> - eltType = tuple - > getElement ( elementNo ) . getType ( ) ; <nl> - } else { <nl> - return true ; <nl> - } <nl> + / / If this is an apply_inst passing the memory address as an indirect <nl> + / / result operand , then we have a call that fills in this result . <nl> + if ( auto * apply = dyn_cast < ApplyInst > ( user ) ) { <nl> + auto conventions = apply - > getSubstCalleeConv ( ) ; <nl> + <nl> + / / If this is an out - parameter , it is like a store . If not , this is an <nl> + / / indirect read which is ok . <nl> + unsigned numIndirectResults = conventions . getNumIndirectSILResults ( ) ; <nl> + unsigned opNum = use - > getOperandNumber ( ) - 1 ; <nl> + if ( opNum > = numIndirectResults ) <nl> + continue ; <nl> + <nl> + / / Forbid multiple assignment . <nl> + if ( getMemoryValue ( ) . getKind ( ) ! = SymbolicValue : : UninitMemory ) <nl> + return error ( evaluator . getUnknown ( addr , UnknownReason : : Default ) ) ; <nl> + <nl> + / / The callee needs to be a direct call to a constant expression . <nl> + auto callResult = computeCallResult ( apply ) ; <nl> + <nl> + / / If the call failed , we ' re done . <nl> + if ( callResult . hasValue ( ) ) <nl> + return error ( * callResult ) ; <nl> + <nl> + / / computeCallResult will have figured out the result and cached it for <nl> + / / us . <nl> + assert ( getMemoryValue ( ) . isConstant ( ) ) ; <nl> + continue ; <nl> + } <nl> + <nl> + / / If it is an index_addr , make sure it is a different address from base . <nl> + if ( auto * iai = dyn_cast < IndexAddrInst > ( user ) ) { <nl> + assert ( use - > get ( ) = = iai - > getBase ( ) ) ; <nl> + if ( auto * ili = dyn_cast < IntegerLiteralInst > ( iai - > getIndex ( ) ) ) { <nl> + if ( ili - > getValue ( ) . getLimitedValue ( ) ! = 0 ) <nl> + continue ; <nl> + } <nl> + return error ( evaluator . getUnknown ( addr , UnknownReason : : Default ) ) ; <nl> + } <nl> + <nl> + if ( auto * teai = dyn_cast < TupleElementAddrInst > ( user ) ) { <nl> + / / Try finding a writer among the users of ` teai ` . For example : <nl> + / / % 179 = alloc_stack $ ( Int32 , Int32 , Int32 , Int32 ) <nl> + / / % 183 = tuple_element_addr % 179 : $ * ( Int32 , Int32 , Int32 , Int32 ) , 3 <nl> + / / copy_addr % 114 to [ initialization ] % 183 : $ * Int32 <nl> + / / % 191 = tuple_element_addr % 179 : $ * ( Int32 , Int32 , Int32 , Int32 ) , 3 <nl> + / / copy_addr [ take ] % 191 to [ initialization ] % 178 : $ * Int32 <nl> + / / <nl> + / / The workflow is : when const - evaluating % 178 , we const - evaluate % 191 , <nl> + / / which in turn triggers const - evaluating % 179 , thereby enter this <nl> + / / function , where ` addrInst ` being % 179 . Among its users , % 191 is not an <nl> + / / initializer , so we skip it ( ` initializeAddressFromSingleWriter ( teai ) ` <nl> + / / below will act as a no - op on it ) . % 183 is a good initializer and can <nl> + / / be const - evaluated ( by const - evaluating % 114 ) . <nl> + <nl> + / / We can ' t forbid multiple assignment here by checking for uninit memory , <nl> + / / because previous TupleElementAddrInsts may have already partially <nl> + / / initialized the memory . However , the recursive call to <nl> + / / ` initializeAddressFromSingleWriter ` below detects and forbids multiple <nl> + / / assignment , so we don ' t need to do it here . <nl> + <nl> + if ( auto failure = initializeAddressFromSingleWriter ( teai ) ) <nl> + return error ( * failure ) ; <nl> + <nl> + / / If this instruction partially initialized the memory , then we must <nl> + / / remember to check later that the memory has been fully initialized . <nl> + if ( getMemoryValue ( ) . getKind ( ) ! = SymbolicValue : : UninitMemory ) <nl> + mustCheckAggregateInitialized = true ; <nl> + <nl> + # ifndef NDEBUG <nl> + / / If all aggregate elements are const , we have successfully <nl> + / / const - evaluated the entire tuple ! <nl> + if ( checkAggregateInitialized ( ) ) <nl> + LLVM_DEBUG ( llvm : : dbgs ( ) < < " Const - evaluated the entire tuple : " ; <nl> + getMemoryValue ( ) . dump ( ) ) ; <nl> + # endif / / NDEBUG <nl> + continue ; <nl> + } <nl> + <nl> + LLVM_DEBUG ( llvm : : dbgs ( ) <nl> + < < " Unknown SingleStore ConstExpr user : " < < * user < < " \ n " ) ; <nl> <nl> - if ( writeOnlyOnce & & <nl> - oldElts [ elementNo ] . getKind ( ) ! = SymbolicValue : : UninitMemory ) { <nl> - / / Cannot overwrite an existing constant . <nl> - return true ; <nl> + / / If this is some other user that we don ' t know about , then we should <nl> + / / treat it conservatively , because it could store into the address . <nl> + return error ( evaluator . getUnknown ( addr , UnknownReason : : Default ) ) ; <nl> } <nl> <nl> - / / Update the indexed element of the aggregate . <nl> - SmallVector < SymbolicValue , 4 > newElts ( oldElts . begin ( ) , oldElts . end ( ) ) ; <nl> - if ( updateIndexedElement ( newElts [ elementNo ] , indices . drop_front ( ) , newElement , <nl> - eltType , writeOnlyOnce , astContext ) ) <nl> - return true ; <nl> + if ( mustCheckAggregateInitialized & & ! checkAggregateInitialized ( ) ) <nl> + return error ( evaluator . getUnknown ( addr , UnknownReason : : Default ) ) ; <nl> <nl> - aggregate = SymbolicValue : : getAggregate ( newElts , astContext ) ; <nl> - return false ; <nl> + return None ; <nl> + } <nl> + <nl> + / / / Find the initializer ( single writer ) of ` addr ` among it users , <nl> + / / / const - evaluate it and store the result into a memory object . <nl> + / / / <nl> + / / / Side effects : Creates a fully - initialized memory object ( on success ) , or a <nl> + / / / memory object containing an unknown ( on failure ) . Inserts the address of <nl> + / / / that memory object into ` calculatedValues ` , with key ` addr ` . <nl> + / / / <nl> + / / / Returns the address of the memory object on success . Returns the unknown on <nl> + / / / failure . <nl> + / / / <nl> + / / / Some use cases are : <nl> + / / / 1 . When analyzing the top - level code involved in a constant expression , we <nl> + / / / can end up demanding values that are returned by address . Handle this by <nl> + / / / finding the temporary stack value ( an alloc_stack inst ) , and calling this <nl> + / / / method on it . <nl> + / / / 2 . When const - evaluating an array via decodeAllocUninitializedArray ( ) , <nl> + / / / do that by const - evaluating the writers of individual array elements . <nl> + / / / <nl> + / / / There are a few forms of writers , such as : <nl> + / / / - store % 3 to % 4 . . . <nl> + / / / - % 8 = pointer_to_address % 7 : $ Builtin . RawPointer to [ strict ] $ * Int32 <nl> + / / / - % 14 = index_addr % 9 : $ * Int32 , % 13 : $ Builtin . Word <nl> + / / / - % 180 = tuple_element_addr % 179 : $ * ( Int32 , Int32 , Int32 , Int32 ) , 3 <nl> + / / / <nl> + / / / Note unlike getConstAddrAndLoadResult ( ) , this method does * not * <nl> + / / / const - evaluate the input ` addr ` by evaluating its operand first , such as % 7 <nl> + / / / above . Instead , it finds a user of % 8 who is the initializer , and uses that <nl> + / / / to set the const value for % 7 . In other words , this method propagates const <nl> + / / / info from result to operand ( e . g . from % 8 to % 7 ) , while <nl> + / / / getConstAddrAndLoadResult ( ) propagates const info from operand to result . <nl> + / / / <nl> + / / / As such , when const - evaluating an address - typed inst such as <nl> + / / / pointer_to_address , if the address is to be written to , caller should call <nl> + / / / this method ( e . g . a [ 3 ] = 17 ) . If the address is to be read ( e . g . let v = <nl> + / / / a [ 3 ] ) , call getConstAddrAndLoadResult ( ) . <nl> + SymbolicValue <nl> + ConstExprFunctionState : : getSingleWriterAddressValue ( SILValue addr ) { <nl> + / / Check to see if we already have an answer . <nl> + auto it = calculatedValues . find ( addr ) ; <nl> + if ( it ! = calculatedValues . end ( ) ) <nl> + return it - > second ; <nl> + <nl> + assert ( addr - > getType ( ) . isAddress ( ) ) ; <nl> + auto * addrInst = dyn_cast < SingleValueInstruction > ( addr ) ; <nl> + if ( ! addrInst ) <nl> + return evaluator . getUnknown ( addr , UnknownReason : : Default ) ; <nl> + <nl> + / / Create a memory object to initialize , and point ` addr ` at it . <nl> + auto memoryAddress = <nl> + createMemoryObject ( addr , SymbolicValue : : getUninitMemory ( ) ) ; <nl> + auto * memoryObject = memoryAddress . getAddressValueMemoryObject ( ) ; <nl> + <nl> + if ( auto failure = initializeAddressFromSingleWriter ( addr ) ) { <nl> + assert ( failure - > getKind ( ) = = SymbolicValue : : Unknown ) ; <nl> + memoryObject - > setValue ( * failure ) ; <nl> + return * failure ; <nl> + } <nl> + if ( ! memoryObject - > getValue ( ) . isConstant ( ) ) { <nl> + auto unknown = evaluator . getUnknown ( addr , UnknownReason : : Default ) ; <nl> + memoryObject - > setValue ( unknown ) ; <nl> + return unknown ; <nl> + } <nl> + <nl> + return memoryAddress ; <nl> } <nl> <nl> / / / Given the operand to a load , resolve it to a constant if possible . <nl> + / / / Also see the comments on getSingleWriterAddressValue ( ) to contrast these 2 <nl> + / / / APIs . <nl> SymbolicValue ConstExprFunctionState : : getConstAddrAndLoadResult ( SILValue addr ) { <nl> auto addrVal = getConstantValue ( addr ) ; <nl> if ( ! addrVal . isConstant ( ) ) <nl> ConstExprFunctionState : : computeFSStore ( SymbolicValue storedCst , SILValue dest ) { <nl> <nl> SmallVector < unsigned , 4 > accessPath ; <nl> auto * memoryObject = it - > second . getAddressValue ( accessPath ) ; <nl> - auto objectVal = memoryObject - > getValue ( ) ; <nl> - auto objectType = memoryObject - > getType ( ) ; <nl> - <nl> - if ( updateIndexedElement ( objectVal , accessPath , storedCst , objectType , <nl> - / * writeOnlyOnce * / false , evaluator . getASTContext ( ) ) ) <nl> - return evaluator . getUnknown ( dest , UnknownReason : : Default ) ; <nl> - <nl> - memoryObject - > setValue ( objectVal ) ; <nl> + memoryObject - > setIndexedElement ( accessPath , storedCst , <nl> + evaluator . getASTContext ( ) ) ; <nl> return None ; <nl> } <nl> <nl> mmm a / test / SILOptimizer / pound_assert . sil <nl> ppp b / test / SILOptimizer / pound_assert . sil <nl> bb0 : <nl> return undef : $ ( ) <nl> } <nl> <nl> - / / Tests that piecewise initialization of memory works , by piecewise <nl> - / / initializing a tuple . <nl> - sil @ piecewiseInit : $ @ convention ( thin ) ( ) - > Bool { <nl> + / / Tests that piecewise initialization of memory works during flow - sensitive <nl> + / / evaluation , by piecewise initializing a tuple in a function . <nl> + sil @ piecewiseInitFlowSensitive : $ @ convention ( thin ) ( ) - > Bool { <nl> bb0 : <nl> / / Allocate and initialize the tuple to ( 1 , 2 ) . <nl> % 0 = alloc_stack $ ( Int64 , Int64 ) , var , name " tup " <nl> bb0 : <nl> return % 15 : $ Bool <nl> } <nl> <nl> + sil @ invokePiecewiseInitFlowSensitiveTest : $ @ convention ( thin ) ( ) - > ( ) { <nl> + % 0 = function_ref @ piecewiseInitFlowSensitive : $ @ convention ( thin ) ( ) - > Bool <nl> + % 1 = apply % 0 ( ) : $ @ convention ( thin ) ( ) - > Bool <nl> + % 2 = struct_extract % 1 : $ Bool , # Bool . _value <nl> + % 3 = string_literal utf8 " " <nl> + % 4 = builtin " poundAssert " ( % 2 : $ Builtin . Int1 , % 3 : $ Builtin . RawPointer ) : $ ( ) <nl> + % ret = tuple ( ) <nl> + return % ret : $ ( ) <nl> + } <nl> + <nl> / / Tests copy_addr interpretation . <nl> sil @ copyAddr : $ @ convention ( thin ) ( ) - > Bool { <nl> / / Allocate an initialize an Int64 to 1 . <nl> sil @ copyAddr : $ @ convention ( thin ) ( ) - > Bool { <nl> return % 10 : $ Bool <nl> } <nl> <nl> - sil @ invokeTests : $ @ convention ( thin ) ( ) - > ( ) { <nl> - % 0 = function_ref @ piecewiseInit : $ @ convention ( thin ) ( ) - > Bool <nl> + sil @ invokeCopyAddrTest : $ @ convention ( thin ) ( ) - > ( ) { <nl> + % 0 = function_ref @ copyAddr : $ @ convention ( thin ) ( ) - > Bool <nl> % 1 = apply % 0 ( ) : $ @ convention ( thin ) ( ) - > Bool <nl> % 2 = struct_extract % 1 : $ Bool , # Bool . _value <nl> % 3 = string_literal utf8 " " <nl> % 4 = builtin " poundAssert " ( % 2 : $ Builtin . Int1 , % 3 : $ Builtin . RawPointer ) : $ ( ) <nl> + % ret = tuple ( ) <nl> + return % ret : $ ( ) <nl> + } <nl> + <nl> + / / A function with @ out result to help with some tests . <nl> + sil @ setInt64To1 : $ @ convention ( thin ) ( ) - > ( @ out Int64 ) { <nl> + bb0 ( % 0 : $ * Int64 ) : <nl> + % 1 = integer_literal $ Builtin . Int64 , 1 <nl> + % 2 = struct $ Int64 ( % 1 : $ Builtin . Int64 ) <nl> + store % 2 to % 0 : $ * Int64 <nl> + % ret = tuple ( ) <nl> + return % ret : $ ( ) <nl> + } <nl> + <nl> + / / Tests that initialization of memory using ` store ` works during top - level <nl> + / / evaluation . <nl> + sil @ storeInitTopLevel : $ @ convention ( thin ) ( ) - > ( ) { <nl> + % 0 = alloc_stack $ Int64 <nl> + % 1 = integer_literal $ Builtin . Int64 , 1 <nl> + % 2 = struct $ Int64 ( % 1 : $ Builtin . Int64 ) <nl> + store % 2 to % 0 : $ * Int64 <nl> + % 4 = load % 0 : $ * Int64 <nl> + % 5 = struct_extract % 4 : $ Int64 , # Int64 . _value <nl> + % 6 = builtin " cmp_eq_Int64 " ( % 1 : $ Builtin . Int64 , % 5 : $ Builtin . Int64 ) : $ Builtin . Int1 <nl> + % 7 = string_literal utf8 " " <nl> + % 8 = builtin " poundAssert " ( % 6 : $ Builtin . Int1 , % 7 : $ Builtin . RawPointer ) : $ ( ) <nl> + dealloc_stack % 0 : $ * Int64 <nl> + % ret = tuple ( ) <nl> + return % ret : $ ( ) <nl> + } <nl> + <nl> + / / Tests that initialization of memory using ` copy_addr ` works during top - level <nl> + / / evaluation . <nl> + sil @ copyInitTopLevel : $ @ convention ( thin ) ( ) - > ( ) { <nl> + % 0 = alloc_stack $ Int64 <nl> + % 1 = alloc_stack $ Int64 <nl> + % 2 = integer_literal $ Builtin . Int64 , 1 <nl> + % 3 = struct $ Int64 ( % 2 : $ Builtin . Int64 ) <nl> + store % 3 to % 0 : $ * Int64 <nl> + copy_addr % 0 to % 1 : $ * Int64 <nl> + % 6 = load % 1 : $ * Int64 <nl> + % 7 = struct_extract % 6 : $ Int64 , # Int64 . _value <nl> + % 8 = builtin " cmp_eq_Int64 " ( % 2 : $ Builtin . Int64 , % 7 : $ Builtin . Int64 ) : $ Builtin . Int1 <nl> + % 9 = string_literal utf8 " " <nl> + % 10 = builtin " poundAssert " ( % 8 : $ Builtin . Int1 , % 9 : $ Builtin . RawPointer ) : $ ( ) <nl> + dealloc_stack % 1 : $ * Int64 <nl> + dealloc_stack % 0 : $ * Int64 <nl> + % ret = tuple ( ) <nl> + return % ret : $ ( ) <nl> + } <nl> + <nl> + / / Tests that initialization of memory using ` apply ` works during top - level <nl> + / / evaluation . <nl> + sil @ applyInitTopLevel : $ @ convention ( thin ) ( ) - > ( ) { <nl> + % 0 = alloc_stack $ Int64 <nl> + % 1 = function_ref @ setInt64To1 : $ @ convention ( thin ) ( ) - > ( @ out Int64 ) <nl> + % 2 = apply % 1 ( % 0 ) : $ @ convention ( thin ) ( ) - > ( @ out Int64 ) <nl> + % 3 = load % 0 : $ * Int64 <nl> + % 4 = struct_extract % 3 : $ Int64 , # Int64 . _value <nl> + % 5 = integer_literal $ Builtin . Int64 , 1 <nl> + % 6 = builtin " cmp_eq_Int64 " ( % 4 : $ Builtin . Int64 , % 5 : $ Builtin . Int64 ) : $ Builtin . Int1 <nl> + % 7 = string_literal utf8 " " <nl> + % 8 = builtin " poundAssert " ( % 6 : $ Builtin . Int1 , % 7 : $ Builtin . RawPointer ) : $ ( ) <nl> + dealloc_stack % 0 : $ * Int64 <nl> + % ret = tuple ( ) <nl> + return % ret : $ ( ) <nl> + } <nl> + <nl> + / / Tests that piecewise initialization of tuple memory works during top - level <nl> + / / evaluation . <nl> + sil @ piecewiseInitTopLevel : $ @ convention ( thin ) ( ) - > ( ) { <nl> + bb0 : <nl> + / / Allocate and initialize the tuple to ( 1 , 2 ) . <nl> + % 0 = alloc_stack $ ( Int64 , Int64 ) , var , name " tup " <nl> + % 1 = tuple_element_addr % 0 : $ * ( Int64 , Int64 ) , 0 <nl> + % 2 = tuple_element_addr % 0 : $ * ( Int64 , Int64 ) , 1 <nl> + % 3 = integer_literal $ Builtin . Int64 , 1 <nl> + % 4 = struct $ Int64 ( % 3 : $ Builtin . Int64 ) <nl> + store % 4 to % 1 : $ * Int64 <nl> + % 6 = integer_literal $ Builtin . Int64 , 2 <nl> + % 7 = struct $ Int64 ( % 6 : $ Builtin . Int64 ) <nl> + store % 7 to % 2 : $ * Int64 <nl> + <nl> + / / Read the first element from the tuple . <nl> + / / TODO : Allow ` begin_access ` in top level initialization . <nl> + / / % 9 = begin_access [ read ] [ static ] % 0 : $ * ( Int64 , Int64 ) <nl> + % 10 = tuple_element_addr % 0 : $ * ( Int64 , Int64 ) , 0 <nl> + % 11 = load % 10 : $ * Int64 <nl> + / / end_access % 9 : $ * ( Int64 , Int64 ) <nl> + <nl> + / / Check that the first element is what we put in . <nl> + % 13 = struct_extract % 11 : $ Int64 , # Int64 . _value <nl> + % 14 = builtin " cmp_eq_Int64 " ( % 3 : $ Builtin . Int64 , % 13 : $ Builtin . Int64 ) : $ Builtin . Int1 <nl> + % 15 = string_literal utf8 " " <nl> + % 16 = builtin " poundAssert " ( % 14 : $ Builtin . Int1 , % 15 : $ Builtin . RawPointer ) : $ ( ) <nl> + <nl> + / / Deallocate and return . <nl> + dealloc_stack % 0 : $ * ( Int64 , Int64 ) <nl> + % ret = tuple ( ) <nl> + return % ret : $ ( ) <nl> + } <nl> <nl> - % 5 = function_ref @ copyAddr : $ @ convention ( thin ) ( ) - > Bool <nl> - % 6 = apply % 5 ( ) : $ @ convention ( thin ) ( ) - > Bool <nl> - % 7 = struct_extract % 6 : $ Bool , # Bool . _value <nl> + / / Tests that top - level evaluation detects memory that gets written to twice . <nl> + sil @ doubleWriteTopLevel : $ @ convention ( thin ) ( ) - > ( ) { <nl> + / / expected - note @ + 1 { { could not fold operation } } <nl> + % 0 = alloc_stack $ Int64 <nl> + % 1 = integer_literal $ Builtin . Int64 , 1 <nl> + % 2 = struct $ Int64 ( % 1 : $ Builtin . Int64 ) <nl> + store % 2 to % 0 : $ * Int64 <nl> + store % 2 to % 0 : $ * Int64 <nl> + % 5 = load % 0 : $ * Int64 <nl> + % 6 = struct_extract % 5 : $ Int64 , # Int64 . _value <nl> + % 7 = builtin " cmp_eq_Int64 " ( % 1 : $ Builtin . Int64 , % 6 : $ Builtin . Int64 ) : $ Builtin . Int1 <nl> % 8 = string_literal utf8 " " <nl> + / / expected - error @ + 1 { { # assert condition not constant } } <nl> % 9 = builtin " poundAssert " ( % 7 : $ Builtin . Int1 , % 8 : $ Builtin . RawPointer ) : $ ( ) <nl> + dealloc_stack % 0 : $ * Int64 <nl> + % ret = tuple ( ) <nl> + return % ret : $ ( ) <nl> + } <nl> <nl> + / / There was a bug where the evalutor would not detect a double - write to a <nl> + / / tuple element at the top level if one of the writes writes an unknown value . <nl> + sil @ doubleWriteTupleElement : $ @ convention ( thin ) ( Int64 ) - > ( ) { <nl> + bb0 ( % arg : $ Int64 ) : <nl> + / / Allocate and initialize the tuple to ( 1 , 2 ) . <nl> + % 0 = alloc_stack $ ( Int64 , Int64 ) , var , name " tup " <nl> + % 1 = tuple_element_addr % 0 : $ * ( Int64 , Int64 ) , 0 <nl> + % 2 = tuple_element_addr % 0 : $ * ( Int64 , Int64 ) , 1 <nl> + % 3 = integer_literal $ Builtin . Int64 , 1 <nl> + % 4 = struct $ Int64 ( % 3 : $ Builtin . Int64 ) <nl> + store % 4 to % 1 : $ * Int64 <nl> + % 6 = integer_literal $ Builtin . Int64 , 2 <nl> + % 7 = struct $ Int64 ( % 6 : $ Builtin . Int64 ) <nl> + store % 7 to % 2 : $ * Int64 <nl> + <nl> + / / Store % arg , whose value is unknown , to the first element of the tuple . <nl> + / / expected - note @ + 1 { { could not fold operation } } <nl> + % addr = tuple_element_addr % 0 : $ * ( Int64 , Int64 ) , 0 <nl> + store % arg to % addr : $ * Int64 <nl> + <nl> + / / Read the first element from the tuple . <nl> + / / TODO : Allow ` begin_access ` in top level initialization . <nl> + / / % 9 = begin_access [ read ] [ static ] % 0 : $ * ( Int64 , Int64 ) <nl> + % 10 = tuple_element_addr % 0 : $ * ( Int64 , Int64 ) , 0 <nl> + % 11 = load % 10 : $ * Int64 <nl> + / / end_access % 9 : $ * ( Int64 , Int64 ) <nl> + <nl> + / / Check that the first element is what we put in . <nl> + % 13 = struct_extract % 11 : $ Int64 , # Int64 . _value <nl> + % 14 = builtin " cmp_eq_Int64 " ( % 3 : $ Builtin . Int64 , % 13 : $ Builtin . Int64 ) : $ Builtin . Int1 <nl> + % 15 = string_literal utf8 " " <nl> + / / expected - error @ + 1 { { # assert condition not constant } } <nl> + % 16 = builtin " poundAssert " ( % 14 : $ Builtin . Int1 , % 15 : $ Builtin . RawPointer ) : $ ( ) <nl> + <nl> + / / Deallocate and return . <nl> + dealloc_stack % 0 : $ * ( Int64 , Int64 ) <nl> % ret = tuple ( ) <nl> return % ret : $ ( ) <nl> } <nl> mmm a / test / SILOptimizer / pound_assert . swift <nl> ppp b / test / SILOptimizer / pound_assert . swift <nl> func invokeMutationTests ( ) { <nl> # assert ( replaceAggregate ( ) ) <nl> # assert ( shouldNotAlias ( ) ) <nl> } <nl> + <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / Evaluating generic functions <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + func genericAdd < T : Numeric > ( _ a : T , _ b : T ) - > T { <nl> + return a + b <nl> + } <nl> + <nl> + func test_genericAdd ( ) { <nl> + # assert ( genericAdd ( 1 , 1 ) = = 2 ) <nl> + } <nl> + <nl> + func test_tupleAsGeneric ( ) { <nl> + func identity < T > ( _ t : T ) - > T { <nl> + return t <nl> + } <nl> + # assert ( identity ( ( 1 , 2 ) ) = = ( 1 , 2 ) ) <nl> + } <nl> + <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / Reduced testcase propagating substitutions around . <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + protocol SubstitutionsP { <nl> + init < T : SubstitutionsP > ( something : T ) <nl> + <nl> + func get ( ) - > Int <nl> + } <nl> + <nl> + struct SubstitutionsX : SubstitutionsP { <nl> + var state : Int <nl> + init < T : SubstitutionsP > ( something : T ) { <nl> + state = something . get ( ) <nl> + } <nl> + func get ( ) - > Int { <nl> + fatalError ( ) <nl> + } <nl> + <nl> + func getState ( ) - > Int { <nl> + return state <nl> + } <nl> + } <nl> + <nl> + struct SubstitutionsY : SubstitutionsP { <nl> + init ( ) { } <nl> + init < T : SubstitutionsP > ( something : T ) { <nl> + } <nl> + <nl> + func get ( ) - > Int { <nl> + return 123 <nl> + } <nl> + } <nl> + func substitutionsF < T : SubstitutionsP > ( _ : T . Type ) - > T { <nl> + return T ( something : SubstitutionsY ( ) ) <nl> + } <nl> + <nl> + func testProto ( ) { <nl> + # assert ( substitutionsF ( SubstitutionsX . self ) . getState ( ) = = 123 ) <nl> + } <nl> + <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / Structs with generics <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + / / Test 1 <nl> + struct S < X , Y > { <nl> + func method < Z > ( _ z : Z ) - > Int { <nl> + return 0 <nl> + } <nl> + } <nl> + <nl> + func callerOfSMethod < U , V , W > ( _ s : S < U , V > , _ w : W ) - > Int { <nl> + return s . method ( w ) <nl> + } <nl> + <nl> + func toplevel ( ) { <nl> + let s = S < Int , Float > ( ) <nl> + # assert ( callerOfSMethod ( s , - 1 ) = = 0 ) <nl> + } <nl> + <nl> + / / Test 2 : test a struct method returning its generic argument . <nl> + struct S2 < X > { <nl> + func method < Z > ( _ z : Z ) - > Z { <nl> + return z <nl> + } <nl> + } <nl> + <nl> + func callerOfS2Method < U , V > ( _ s : S2 < U > , _ v : V ) - > V { <nl> + return s . method ( v ) <nl> + } <nl> + <nl> + func testStructMethodReturningGenericParam ( ) { <nl> + let s = S2 < Float > ( ) <nl> + # assert ( callerOfS2Method ( s , - 1 ) = = - 1 ) <nl> + } <nl> + <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / Test that the order in which the generic parameters are declared doesn ' t <nl> + / / affect the interpreter . <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + protocol Proto { <nl> + func amethod < U > ( _ u : U ) - > Int <nl> + } <nl> + <nl> + func callMethod < U , T : Proto > ( _ a : T , _ u : U ) - > Int { <nl> + return a . amethod ( u ) <nl> + } <nl> + <nl> + / / Test 1 <nl> + struct Sp : Proto { <nl> + func amethod < U > ( _ u : U ) - > Int { <nl> + return 0 <nl> + } <nl> + } <nl> + <nl> + func testProtocolMethod ( ) { <nl> + let s = Sp ( ) <nl> + # assert ( callMethod ( s , 10 ) = = 0 ) <nl> + } <nl> + <nl> + / / Test 2 <nl> + struct GenericS < P > : Proto { <nl> + func amethod < U > ( _ u : U ) - > Int { <nl> + return 12 <nl> + } <nl> + } <nl> + <nl> + func testProtocolMethodForGenericStructs ( ) { <nl> + let s = GenericS < Int > ( ) <nl> + # assert ( callMethod ( s , 10 ) = = 12 ) <nl> + } <nl> + <nl> + / / Test 3 ( with generic fields ) <nl> + struct GenericS2 < P : Equatable > : Proto { <nl> + var fld1 : P <nl> + var fld2 : P <nl> + <nl> + init ( _ p : P , _ q : P ) { <nl> + fld1 = p <nl> + fld2 = q <nl> + } <nl> + <nl> + func amethod < U > ( _ u : U ) - > Int { <nl> + if ( fld1 = = fld2 ) { <nl> + return 15 <nl> + } <nl> + return 0 <nl> + } <nl> + } <nl> + <nl> + func testProtocolMethodForStructsWithGenericFields ( ) { <nl> + let s = GenericS2 < Int > ( 1 , 1 ) <nl> + # assert ( callMethod ( s , 10 ) = = 15 ) <nl> + } <nl> + <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / Structs with generics and protocols with associated types . <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + protocol ProtoWithAssocType { <nl> + associatedtype U <nl> + <nl> + func amethod ( _ u : U ) - > U <nl> + } <nl> + <nl> + struct St < X , Y > : ProtoWithAssocType { <nl> + typealias U = X <nl> + <nl> + func amethod ( _ x : X ) - > X { <nl> + return x <nl> + } <nl> + } <nl> + <nl> + func callerOfStMethod < P , Q > ( _ s : St < P , Q > , _ p : P ) - > P { <nl> + return s . amethod ( p ) <nl> + } <nl> + <nl> + func testProtoWithAssocTypes ( ) { <nl> + let s = St < Int , Float > ( ) <nl> + # assert ( callerOfStMethod ( s , 11 ) = = 11 ) <nl> + } <nl> + <nl> + / / Test 2 : test a protocol method returning its generic argument . <nl> + protocol ProtoWithGenericMethod { <nl> + func amethod < U > ( _ u : U ) - > U <nl> + } <nl> + <nl> + <nl> + struct SProtoWithGenericMethod < X > : ProtoWithGenericMethod { <nl> + func amethod < Z > ( _ z : Z ) - > Z { <nl> + return z <nl> + } <nl> + } <nl> + <nl> + func callerOfGenericProtoMethod < S : ProtoWithGenericMethod , V > ( _ s : S , <nl> + _ v : V ) - > V { <nl> + return s . amethod ( v ) <nl> + } <nl> + <nl> + func testProtoWithGenericMethod ( ) { <nl> + let s = SProtoWithGenericMethod < Float > ( ) <nl> + # assert ( callerOfGenericProtoMethod ( s , - 1 ) = = - 1 ) <nl> + } <nl> + <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / Converting a struct instance to protocol instance is not supported yet . <nl> + / / This requires handling init_existential_addr instruction . Once they are <nl> + / / supported , the following static assert must pass . For now , a workaround is <nl> + / / to use generic parameters with protocol constraints in the interpretable <nl> + / / code fragments . <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + protocol ProtoSimple { <nl> + func amethod ( ) - > Int <nl> + } <nl> + <nl> + func callProtoSimpleMethod ( _ p : ProtoSimple ) - > Int { <nl> + return p . amethod ( ) <nl> + } <nl> + <nl> + struct SPsimp : ProtoSimple { <nl> + func amethod ( ) - > Int { <nl> + return 0 <nl> + } <nl> + } <nl> + <nl> + func testStructPassedAsProtocols ( ) { <nl> + let s = SPsimp ( ) <nl> + # assert ( callProtoSimpleMethod ( s ) = = 0 ) / / expected - error { { # assert condition not constant } } <nl> + / / expected - note @ - 1 { { could not fold operation } } <nl> + } <nl>
Merge pull request from apple / marcrasi - const - evaluator - part - 3
apple/swift
f98d7bd5c0aa252c0dbfec50514927bc86b6e846
2019-01-05T01:30:04Z
mmm a / include / swift / SILOptimizer / Utils / OwnershipOptUtils . h <nl> ppp b / include / swift / SILOptimizer / Utils / OwnershipOptUtils . h <nl> struct OwnershipFixupContext { <nl> / / / Namely , we do not support RAUWing values with ValueOwnershipKind : : None <nl> / / / that have uses that do not require ValueOwnershipKind : : None or <nl> / / / ValueOwnershipKind : : Any . <nl> - static bool canFixUpOwnershipForRAUW ( SingleValueInstruction * oldValue , <nl> + static bool canFixUpOwnershipForRAUW ( const SingleValueInstruction * oldValue , <nl> SILValue newValue ) ; <nl> } ; <nl> <nl> mmm a / lib / SIL / IR / SILInstruction . cpp <nl> ppp b / lib / SIL / IR / SILInstruction . cpp <nl> namespace { <nl> return true ; <nl> } <nl> <nl> + bool visitDestructureStructInst ( const DestructureStructInst * RHS ) { <nl> + return true ; <nl> + } <nl> + <nl> + bool visitDestructureTupleInst ( const DestructureTupleInst * RHS ) { <nl> + return true ; <nl> + } <nl> + <nl> bool visitAllocRefInst ( const AllocRefInst * RHS ) { <nl> auto * LHSInst = cast < AllocRefInst > ( LHS ) ; <nl> auto LHSTypes = LHSInst - > getTailAllocatedTypes ( ) ; <nl> mmm a / lib / SILOptimizer / Transforms / CSE . cpp <nl> ppp b / lib / SILOptimizer / Transforms / CSE . cpp <nl> <nl> # define DEBUG_TYPE " sil - cse " <nl> # include " swift / SIL / DebugUtils . h " <nl> # include " swift / SIL / Dominance . h " <nl> + # include " swift / SIL / InstructionUtils . h " <nl> + # include " swift / SIL / OwnershipUtils . h " <nl> # include " swift / SIL / SILCloner . h " <nl> # include " swift / SIL / SILModule . h " <nl> # include " swift / SIL / SILOpenedArchetypesTracker . h " <nl> <nl> # include " swift / SILOptimizer / Analysis / SimplifyInstruction . h " <nl> # include " swift / SILOptimizer / PassManager / Passes . h " <nl> # include " swift / SILOptimizer / PassManager / Transforms . h " <nl> + # include " swift / SILOptimizer / Utils / BasicBlockOptUtils . h " <nl> # include " swift / SILOptimizer / Utils / InstOptUtils . h " <nl> + # include " swift / SILOptimizer / Utils / OwnershipOptUtils . h " <nl> # include " swift / SILOptimizer / Utils / SILInliner . h " <nl> # include " swift / SILOptimizer / Utils / SILOptFunctionBuilder . h " <nl> - # include " swift / SILOptimizer / Utils / BasicBlockOptUtils . h " <nl> # include " llvm / ADT / Hashing . h " <nl> # include " llvm / ADT / STLExtras . h " <nl> # include " llvm / ADT / ScopedHashTable . h " <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> } <nl> <nl> hash_code visitBridgeObjectToRefInst ( BridgeObjectToRefInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitBridgeObjectToWordInst ( BridgeObjectToWordInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitClassifyBridgeObjectInst ( ClassifyBridgeObjectInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitValueToBridgeObjectInst ( ValueToBridgeObjectInst * X ) { <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> } <nl> <nl> hash_code visitRefToBridgeObjectInst ( RefToBridgeObjectInst * X ) { <nl> + if ( X - > getFunction ( ) - > hasOwnership ( ) ) { <nl> + auto TransformedOpValues = <nl> + X - > getOperandValues ( lookThroughOwnershipInsts , false ) ; <nl> + return llvm : : hash_combine ( <nl> + X - > getKind ( ) , X - > getType ( ) , <nl> + llvm : : hash_combine_range ( TransformedOpValues . begin ( ) , <nl> + TransformedOpValues . end ( ) ) ) ; <nl> + } <nl> OperandValueArrayRef Operands ( X - > getAllOperands ( ) ) ; <nl> return llvm : : hash_combine ( <nl> X - > getKind ( ) , X - > getType ( ) , <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> } <nl> <nl> hash_code visitUncheckedTrivialBitCastInst ( UncheckedTrivialBitCastInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitUncheckedBitwiseCastInst ( UncheckedBitwiseCastInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitUncheckedAddrCastInst ( UncheckedAddrCastInst * X ) { <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> } <nl> <nl> hash_code visitProjectBoxInst ( ProjectBoxInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitRefToRawPointerInst ( RefToRawPointerInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitRawPointerToRefInst ( RawPointerToRefInst * X ) { <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> # include " swift / AST / ReferenceStorage . def " <nl> <nl> hash_code visitUpcastInst ( UpcastInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitStringLiteralInst ( StringLiteralInst * X ) { <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> hash_code visitStructInst ( StructInst * X ) { <nl> / / This is safe since we are hashing the operands using the actual pointer <nl> / / values of the values being used by the operand . <nl> + if ( X - > getFunction ( ) - > hasOwnership ( ) ) { <nl> + auto TransformedOpValues = <nl> + X - > getOperandValues ( lookThroughOwnershipInsts , false ) ; <nl> + return llvm : : hash_combine ( <nl> + X - > getKind ( ) , X - > getStructDecl ( ) , <nl> + llvm : : hash_combine_range ( TransformedOpValues . begin ( ) , <nl> + TransformedOpValues . end ( ) ) ) ; <nl> + } <nl> OperandValueArrayRef Operands ( X - > getAllOperands ( ) ) ; <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getStructDecl ( ) , <nl> - llvm : : hash_combine_range ( Operands . begin ( ) , Operands . end ( ) ) ) ; <nl> + return llvm : : hash_combine ( <nl> + X - > getKind ( ) , X - > getStructDecl ( ) , <nl> + llvm : : hash_combine_range ( Operands . begin ( ) , Operands . end ( ) ) ) ; <nl> } <nl> <nl> hash_code visitStructExtractInst ( StructExtractInst * X ) { <nl> return llvm : : hash_combine ( X - > getKind ( ) , X - > getStructDecl ( ) , X - > getField ( ) , <nl> - X - > getOperand ( ) ) ; <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitStructElementAddrInst ( StructElementAddrInst * X ) { <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> X - > getOperand ( ) ) ; <nl> } <nl> <nl> + hash_code visitDestructureStructInst ( DestructureStructInst * X ) { <nl> + return llvm : : hash_combine ( X - > getKind ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> + } <nl> + <nl> hash_code visitCondFailInst ( CondFailInst * X ) { <nl> return llvm : : hash_combine ( X - > getKind ( ) , X - > getOperand ( ) ) ; <nl> } <nl> <nl> hash_code visitClassMethodInst ( ClassMethodInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , <nl> - X - > getType ( ) , <nl> - X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitSuperMethodInst ( SuperMethodInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , <nl> - X - > getType ( ) , <nl> - X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitTupleInst ( TupleInst * X ) { <nl> + if ( X - > getFunction ( ) - > hasOwnership ( ) ) { <nl> + auto TransformedOpValues = <nl> + X - > getOperandValues ( lookThroughOwnershipInsts , false ) ; <nl> + return llvm : : hash_combine ( <nl> + X - > getKind ( ) , X - > getTupleType ( ) , <nl> + llvm : : hash_combine_range ( TransformedOpValues . begin ( ) , <nl> + TransformedOpValues . end ( ) ) ) ; <nl> + } <nl> OperandValueArrayRef Operands ( X - > getAllOperands ( ) ) ; <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getTupleType ( ) , <nl> - llvm : : hash_combine_range ( Operands . begin ( ) , Operands . end ( ) ) ) ; <nl> + return llvm : : hash_combine ( <nl> + X - > getKind ( ) , X - > getTupleType ( ) , <nl> + llvm : : hash_combine_range ( Operands . begin ( ) , Operands . end ( ) ) ) ; <nl> } <nl> <nl> hash_code visitTupleExtractInst ( TupleExtractInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getTupleType ( ) , X - > getFieldIndex ( ) , <nl> - X - > getOperand ( ) ) ; <nl> + return llvm : : hash_combine ( X - > getKind ( ) , X - > getTupleType ( ) , <nl> + X - > getFieldIndex ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> } <nl> <nl> hash_code visitTupleElementAddrInst ( TupleElementAddrInst * X ) { <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> X - > getOperand ( ) ) ; <nl> } <nl> <nl> + hash_code visitDestructureTupleInst ( DestructureTupleInst * X ) { <nl> + return llvm : : hash_combine ( X - > getKind ( ) , <nl> + lookThroughOwnershipInsts ( X - > getOperand ( ) ) ) ; <nl> + } <nl> + <nl> hash_code visitMetatypeInst ( MetatypeInst * X ) { <nl> return llvm : : hash_combine ( X - > getKind ( ) , X - > getType ( ) ) ; <nl> } <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> } <nl> <nl> hash_code visitApplyInst ( ApplyInst * X ) { <nl> + if ( X - > getFunction ( ) - > hasOwnership ( ) ) { <nl> + auto TransformedOpValues = <nl> + X - > getOperandValues ( lookThroughOwnershipInsts , false ) ; <nl> + return llvm : : hash_combine ( <nl> + X - > getKind ( ) , X - > getCallee ( ) , <nl> + llvm : : hash_combine_range ( TransformedOpValues . begin ( ) , <nl> + TransformedOpValues . end ( ) ) ) ; <nl> + } <nl> OperandValueArrayRef Operands ( X - > getAllOperands ( ) ) ; <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getCallee ( ) , <nl> - llvm : : hash_combine_range ( Operands . begin ( ) , <nl> - Operands . end ( ) ) , <nl> - X - > hasSubstitutions ( ) ) ; <nl> + return llvm : : hash_combine ( <nl> + X - > getKind ( ) , X - > getCallee ( ) , <nl> + llvm : : hash_combine_range ( Operands . begin ( ) , Operands . end ( ) ) ) ; <nl> } <nl> <nl> hash_code visitBuiltinInst ( BuiltinInst * X ) { <nl> + if ( X - > getFunction ( ) - > hasOwnership ( ) ) { <nl> + auto TransformedOpValues = <nl> + X - > getOperandValues ( lookThroughOwnershipInsts , false ) ; <nl> + return llvm : : hash_combine ( <nl> + X - > getKind ( ) , X - > getName ( ) . get ( ) , <nl> + llvm : : hash_combine_range ( TransformedOpValues . begin ( ) , <nl> + TransformedOpValues . end ( ) ) , <nl> + X - > hasSubstitutions ( ) ) ; <nl> + } <nl> OperandValueArrayRef Operands ( X - > getAllOperands ( ) ) ; <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getName ( ) . get ( ) , <nl> - llvm : : hash_combine_range ( Operands . begin ( ) , <nl> - Operands . end ( ) ) , <nl> - X - > hasSubstitutions ( ) ) ; <nl> + return llvm : : hash_combine ( <nl> + X - > getKind ( ) , X - > getName ( ) . get ( ) , <nl> + llvm : : hash_combine_range ( Operands . begin ( ) , Operands . end ( ) ) , <nl> + X - > hasSubstitutions ( ) ) ; <nl> } <nl> - <nl> + <nl> hash_code visitEnumInst ( EnumInst * X ) { <nl> / / We hash the enum by hashing its kind , element , and operand if it has one . <nl> if ( ! X - > hasOperand ( ) ) <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> } <nl> <nl> hash_code visitUncheckedRefCastInst ( UncheckedRefCastInst * X ) { <nl> - return llvm : : hash_combine ( X - > getKind ( ) , X - > getOperand ( ) , X - > getType ( ) ) ; <nl> + return llvm : : hash_combine ( <nl> + X - > getKind ( ) , lookThroughOwnershipInsts ( X - > getOperand ( ) ) , X - > getType ( ) ) ; <nl> } <nl> <nl> hash_code visitSelectEnumInstBase ( SelectEnumInstBase * X ) { <nl> class HashVisitor : public SILInstructionVisitor < HashVisitor , llvm : : hash_code > { <nl> auto ArchetypeTy = X - > getType ( ) . castTo < ArchetypeType > ( ) ; <nl> auto ConformsTo = ArchetypeTy - > getConformsTo ( ) ; <nl> return llvm : : hash_combine ( <nl> - X - > getKind ( ) , X - > getOperand ( ) , <nl> + X - > getKind ( ) , lookThroughOwnershipInsts ( X - > getOperand ( ) ) , <nl> llvm : : hash_combine_range ( ConformsTo . begin ( ) , ConformsTo . end ( ) ) ) ; <nl> } <nl> } ; <nl> bool llvm : : DenseMapInfo < SimpleValue > : : isEqual ( SimpleValue LHS , <nl> auto ROpen = dyn_cast < OpenExistentialRefInst > ( RHSI ) ; <nl> if ( LOpen & & ROpen ) { <nl> / / Check operands . <nl> - if ( LOpen - > getOperand ( ) ! = ROpen - > getOperand ( ) ) <nl> + auto LOp = LOpen - > getOperand ( ) ; <nl> + auto ROp = ROpen - > getOperand ( ) ; <nl> + if ( lookThroughOwnershipInsts ( LOp ) ! = lookThroughOwnershipInsts ( ROp ) ) <nl> return false ; <nl> <nl> / / Consider the types of two open_existential_ref instructions to be equal , <nl> bool llvm : : DenseMapInfo < SimpleValue > : : isEqual ( SimpleValue LHS , <nl> <nl> return true ; <nl> } <nl> - return LHSI - > getKind ( ) = = RHSI - > getKind ( ) & & LHSI - > isIdenticalTo ( RHSI ) ; <nl> + auto opCmp = [ & ] ( const SILValue op1 , const SILValue op2 ) - > bool { <nl> + if ( op1 = = op2 ) <nl> + return true ; <nl> + if ( lookThroughOwnershipInsts ( op1 ) = = lookThroughOwnershipInsts ( op2 ) ) <nl> + return true ; <nl> + return false ; <nl> + } ; <nl> + auto canHandleOwnershipConversion = [ ] ( const SILInstruction * lhs , <nl> + const SILInstruction * rhs ) - > bool { <nl> + if ( ! lhs - > getFunction ( ) - > hasOwnership ( ) ) <nl> + return true ; <nl> + / / TODO : Support MultipleValueInstructionResult in OSSA RAUW utility and <nl> + / / extend it here as well <nl> + if ( ! isa < SingleValueInstruction > ( lhs ) ) <nl> + return false ; <nl> + return OwnershipFixupContext : : canFixUpOwnershipForRAUW ( <nl> + cast < SingleValueInstruction > ( lhs ) , cast < SingleValueInstruction > ( rhs ) ) ; <nl> + } ; <nl> + return LHSI - > getKind ( ) = = RHSI - > getKind ( ) & & <nl> + LHSI - > isIdenticalTo ( RHSI , opCmp ) & & <nl> + ( LHSI = = RHSI | | canHandleOwnershipConversion ( LHSI , RHSI ) ) ; <nl> } <nl> <nl> + namespace { <nl> + / / A very simple cloner for cloning instructions inside <nl> + / / the same function . The only interesting thing it does <nl> + / / is remapping the archetypes when it is required . <nl> + class InstructionCloner : public SILCloner < InstructionCloner > { <nl> + friend class SILCloner < InstructionCloner > ; <nl> + friend class SILInstructionVisitor < InstructionCloner > ; <nl> + SILInstruction * Result = nullptr ; <nl> + <nl> + public : <nl> + InstructionCloner ( SILFunction * F ) : SILCloner ( * F ) { } <nl> + <nl> + static SILInstruction * doIt ( SILInstruction * I ) { <nl> + InstructionCloner TC ( I - > getFunction ( ) ) ; <nl> + return TC . clone ( I ) ; <nl> + } <nl> + <nl> + SILInstruction * clone ( SILInstruction * I ) { <nl> + visit ( I ) ; <nl> + return Result ; <nl> + } <nl> + <nl> + void postProcess ( SILInstruction * Orig , SILInstruction * Cloned ) { <nl> + assert ( Orig - > getFunction ( ) = = & getBuilder ( ) . getFunction ( ) & & <nl> + " cloning between functions is not supported " ) ; <nl> + <nl> + Result = Cloned ; <nl> + SILCloner < InstructionCloner > : : postProcess ( Orig , Cloned ) ; <nl> + } <nl> + SILValue getMappedValue ( SILValue Value ) { return Value ; } <nl> + SILBasicBlock * remapBasicBlock ( SILBasicBlock * BB ) { return BB ; } <nl> + } ; <nl> + } / / end anonymous namespace <nl> + <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> / / CSE Interface <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> class CSE { <nl> SideEffectAnalysis * SEA ; <nl> <nl> SILOptFunctionBuilder & FuncBuilder ; <nl> - <nl> + <nl> + SILOpenedArchetypesTracker & OpenedArchetypesTracker ; <nl> + <nl> + InstructionCloner & Cloner ; <nl> + <nl> + DeadEndBlocks & DeadEndBBs ; <nl> + <nl> + OwnershipFixupContext & FixupCtx ; <nl> + <nl> / / / The set of calls to lazy property getters which can be replace by a direct <nl> / / / load of the property value . <nl> llvm : : SmallVector < ApplyInst * , 8 > lazyPropertyGetters ; <nl> <nl> CSE ( bool RunsOnHighLevelSil , SideEffectAnalysis * SEA , <nl> - SILOptFunctionBuilder & FuncBuilder ) <nl> + SILOptFunctionBuilder & FuncBuilder , <nl> + SILOpenedArchetypesTracker & OpenedArchetypesTracker , <nl> + InstructionCloner & Cloner , DeadEndBlocks & DeadEndBBs , <nl> + OwnershipFixupContext & FixupCtx ) <nl> : SEA ( SEA ) , FuncBuilder ( FuncBuilder ) , <nl> - RunsOnHighLevelSil ( RunsOnHighLevelSil ) { } <nl> + OpenedArchetypesTracker ( OpenedArchetypesTracker ) , Cloner ( Cloner ) , <nl> + DeadEndBBs ( DeadEndBBs ) , FixupCtx ( FixupCtx ) , <nl> + RunsOnHighLevelSil ( RunsOnHighLevelSil ) { <nl> + Cloner . getBuilder ( ) . setOpenedArchetypesTracker ( & OpenedArchetypesTracker ) ; <nl> + } <nl> <nl> bool processFunction ( SILFunction & F , DominanceInfo * DT ) ; <nl> <nl> bool CSE : : processLazyPropertyGetters ( ) { <nl> return changed ; <nl> } <nl> <nl> - namespace { <nl> - / / A very simple cloner for cloning instructions inside <nl> - / / the same function . The only interesting thing it does <nl> - / / is remapping the archetypes when it is required . <nl> - class InstructionCloner : public SILCloner < InstructionCloner > { <nl> - friend class SILCloner < InstructionCloner > ; <nl> - friend class SILInstructionVisitor < InstructionCloner > ; <nl> - SILInstruction * Result = nullptr ; <nl> - public : <nl> - InstructionCloner ( SILFunction * F ) : SILCloner ( * F ) { } <nl> - <nl> - static SILInstruction * doIt ( SILInstruction * I ) { <nl> - InstructionCloner TC ( I - > getFunction ( ) ) ; <nl> - return TC . clone ( I ) ; <nl> - } <nl> - <nl> - SILInstruction * clone ( SILInstruction * I ) { <nl> - visit ( I ) ; <nl> - return Result ; <nl> - } <nl> - <nl> - void postProcess ( SILInstruction * Orig , SILInstruction * Cloned ) { <nl> - assert ( Orig - > getFunction ( ) = = & getBuilder ( ) . getFunction ( ) & & <nl> - " cloning between functions is not supported " ) ; <nl> - <nl> - Result = Cloned ; <nl> - SILCloner < InstructionCloner > : : postProcess ( Orig , Cloned ) ; <nl> - } <nl> - SILValue getMappedValue ( SILValue Value ) { <nl> - return Value ; <nl> - } <nl> - SILBasicBlock * remapBasicBlock ( SILBasicBlock * BB ) { return BB ; } <nl> - } ; <nl> - } / / end anonymous namespace <nl> - <nl> / / / Update SIL basic block ' s arguments types which refer to opened <nl> / / / archetypes . Replace such types by performing type substitutions <nl> / / / according to the provided type substitution map . <nl> bool CSE : : processOpenExistentialRef ( OpenExistentialRefInst * Inst , <nl> NewOpenedArchetype ) ; <nl> } <nl> } <nl> + <nl> / / Now process candidates . <nl> - / / TODO : Move it to CSE instance to avoid recreating it every time ? <nl> - SILOpenedArchetypesTracker OpenedArchetypesTracker ( Inst - > getFunction ( ) ) ; <nl> / / Register the new archetype to be used . <nl> OpenedArchetypesTracker . registerOpenedArchetypes ( VI ) ; <nl> - / / Use a cloner . It makes copying the instruction and remapping of <nl> - / / opened archetypes trivial . <nl> - InstructionCloner Cloner ( Inst - > getFunction ( ) ) ; <nl> Cloner . registerOpenedExistentialRemapping ( <nl> OldOpenedArchetype - > castTo < ArchetypeType > ( ) , NewOpenedArchetype ) ; <nl> auto & Builder = Cloner . getBuilder ( ) ; <nl> - Builder . setOpenedArchetypesTracker ( & OpenedArchetypesTracker ) ; <nl> <nl> llvm : : SmallPtrSet < SILInstruction * , 16 > Processed ; <nl> / / Now clone each candidate and replace the opened archetype <nl> bool CSE : : processNode ( DominanceInfoNode * Node ) { <nl> / / If the instruction can be simplified ( e . g . X + 0 = X ) then replace it with <nl> / / its simpler value . <nl> if ( SILValue V = simplifyInstruction ( Inst ) ) { <nl> - LLVM_DEBUG ( llvm : : dbgs ( ) < < " SILCSE SIMPLIFY : " < < * Inst < < " to : " < < * V <nl> - < < ' \ n ' ) ; <nl> - nextI = replaceAllSimplifiedUsesAndErase ( Inst , V ) ; <nl> + LLVM_DEBUG ( llvm : : dbgs ( ) <nl> + < < " SILCSE SIMPLIFY : " < < * Inst < < " to : " < < * V < < ' \ n ' ) ; <nl> + nextI = replaceAllSimplifiedUsesAndErase ( Inst , V , nullptr , nullptr , <nl> + & DeadEndBBs ) ; <nl> Changed = true ; <nl> + + NumSimplify ; <nl> continue ; <nl> bool CSE : : processNode ( DominanceInfoNode * Node ) { <nl> / / match itself . <nl> assert ( Inst - > isIdenticalTo ( Inst ) & & <nl> " Inst must match itself for map to work " ) ; <nl> + assert ( llvm : : DenseMapInfo < SimpleValue > : : isEqual ( Inst , Inst ) & & <nl> + " Inst must match itself for map to work " ) ; <nl> <nl> / / Now that we know we have an instruction we understand see if the <nl> / / instruction has an available value . If so , use it . <nl> bool CSE : : processNode ( DominanceInfoNode * Node ) { <nl> lazyPropertyGetters . push_back ( AI ) ; <nl> continue ; <nl> } <nl> - <nl> - / / Instructions producing a new opened archetype need a special handling , <nl> - / / because replacing these instructions may require a replacement <nl> - / / of the opened archetype type operands in some of the uses . <nl> - if ( ! isa < OpenExistentialRefInst > ( Inst ) <nl> - | | processOpenExistentialRef ( <nl> - cast < OpenExistentialRefInst > ( Inst ) , <nl> - cast < OpenExistentialRefInst > ( AvailInst ) ) ) { <nl> - / / processOpenExistentialRef may delete instructions other than Inst , so <nl> - / / nextI must be reassigned . <nl> - nextI = std : : next ( Inst - > getIterator ( ) ) ; <nl> - Inst - > replaceAllUsesPairwiseWith ( AvailInst ) ; <nl> - Inst - > eraseFromParent ( ) ; <nl> + if ( ! isa < OpenExistentialRefInst > ( Inst ) | | <nl> + processOpenExistentialRef ( cast < OpenExistentialRefInst > ( Inst ) , <nl> + cast < OpenExistentialRefInst > ( AvailInst ) ) ) { <nl> + if ( Inst - > getResults ( ) . empty ( ) ) { <nl> + nextI = std : : next ( Inst - > getIterator ( ) ) ; <nl> + Inst - > eraseFromParent ( ) ; <nl> + Changed = true ; <nl> + + + NumCSE ; <nl> + continue ; <nl> + } <nl> + if ( ! Inst - > getFunction ( ) - > hasOwnership ( ) ) { <nl> + Inst - > replaceAllUsesPairwiseWith ( AvailInst ) ; <nl> + nextI = std : : next ( Inst - > getIterator ( ) ) ; <nl> + Inst - > eraseFromParent ( ) ; <nl> + Changed = true ; <nl> + + + NumCSE ; <nl> + continue ; <nl> + } <nl> + / / Replace SingleValueInstruction using OSSA RAUW here <nl> + / / TODO : Support MultipleValueInstructionResult in OSSA RAUW utility and <nl> + / / extend it here as well <nl> + nextI = FixupCtx . replaceAllUsesAndEraseFixingOwnership ( <nl> + cast < SingleValueInstruction > ( Inst ) , <nl> + cast < SingleValueInstruction > ( AvailInst ) ) ; <nl> Changed = true ; <nl> + + NumCSE ; <nl> continue ; <nl> bool CSE : : canHandle ( SILInstruction * Inst ) { <nl> case SILInstructionKind : : ThinFunctionToPointerInst : <nl> case SILInstructionKind : : PointerToThinFunctionInst : <nl> case SILInstructionKind : : MarkDependenceInst : <nl> - case SILInstructionKind : : OpenExistentialRefInst : <nl> case SILInstructionKind : : InitExistentialMetatypeInst : <nl> case SILInstructionKind : : WitnessMethodInst : <nl> + case SILInstructionKind : : DestructureStructInst : <nl> + case SILInstructionKind : : DestructureTupleInst : <nl> / / Intentionally we don ' t handle ( prev_ ) dynamic_function_ref . <nl> / / They change at runtime . <nl> # define LOADABLE_REF_STORAGE ( Name , . . . ) \ <nl> bool CSE : : canHandle ( SILInstruction * Inst ) { <nl> case SILInstructionKind : : Name # # ToRefInst : <nl> # include " swift / AST / ReferenceStorage . def " <nl> return true ; <nl> + / / TODO : open_existential_ref is not handled in OSSA currently <nl> + / / This is because it is non trivial to ownership rauw copy_value users of a <nl> + / / redundant open_existential_ref . Suppose we have an ` open_existential_ref ` <nl> + / / and we are trying to replace it with another ` open_existential_ref ` of <nl> + / / different type . If one of the users of the old ` open_existential_ref ` is <nl> + / / a ` copy_value ` , we cannot just replace the use . Because ` copy_value ` ' s <nl> + / / result type will be the old type as well . <nl> + / / <nl> + / / In all other places in the compiler where such a rauw needs to be <nl> + / / handled , a remapping type is initialized in the cloner and the <nl> + / / instruction is cloned before providing to the rauw utility . This would <nl> + / / correctly replace all the result types . But since copy_value does not <nl> + / / have type dependent operands , we cannot handle it in a similar way . <nl> + / / <nl> + / / This is currently a TODO until we can implement a clean way to fix this <nl> + / / issue . <nl> + case SILInstructionKind : : OpenExistentialRefInst : <nl> + return ! Inst - > getFunction ( ) - > hasOwnership ( ) ; <nl> default : <nl> return false ; <nl> } <nl> class SILCSE : public SILFunctionTransform { <nl> bool RunsOnHighLevelSil ; <nl> <nl> void run ( ) override { <nl> - / / FIXME : We should be able to support ownership . <nl> - if ( getFunction ( ) - > hasOwnership ( ) ) <nl> - return ; <nl> - <nl> LLVM_DEBUG ( llvm : : dbgs ( ) < < " * * * * * CSE on function : " <nl> < < getFunction ( ) - > getName ( ) < < " * * * * * \ n " ) ; <nl> <nl> class SILCSE : public SILFunctionTransform { <nl> auto * SEA = PM - > getAnalysis < SideEffectAnalysis > ( ) ; <nl> SILOptFunctionBuilder FuncBuilder ( * this ) ; <nl> <nl> - CSE C ( RunsOnHighLevelSil , SEA , FuncBuilder ) ; <nl> + auto * Fn = getFunction ( ) ; <nl> + SILOpenedArchetypesTracker OpenedArchetypesTracker ( Fn ) ; <nl> + InstructionCloner Cloner ( Fn ) ; <nl> + DeadEndBlocks DeadEndBBs ( Fn ) ; <nl> + JointPostDominanceSetComputer Computer ( DeadEndBBs ) ; <nl> + OwnershipFixupContext FixupCtx { / * eraseNotify * / nullptr , <nl> + / * newInstNotify * / nullptr , DeadEndBBs , <nl> + Computer } ; <nl> + CSE C ( RunsOnHighLevelSil , SEA , FuncBuilder , OpenedArchetypesTracker , Cloner , <nl> + DeadEndBBs , FixupCtx ) ; <nl> bool Changed = false ; <nl> <nl> / / Perform the traditional CSE . <nl> - Changed | = C . processFunction ( * getFunction ( ) , DA - > get ( getFunction ( ) ) ) ; <nl> + Changed | = C . processFunction ( * Fn , DA - > get ( Fn ) ) ; <nl> <nl> / / Perform CSE of existential and witness_method instructions . <nl> - Changed | = CSEExistentialCalls ( getFunction ( ) , <nl> - DA - > get ( getFunction ( ) ) ) ; <nl> + Changed | = CSEExistentialCalls ( Fn , DA - > get ( Fn ) ) ; <nl> <nl> / / Handle calls to lazy property getters , which are collected in <nl> / / processFunction ( ) . <nl> if ( C . processLazyPropertyGetters ( ) ) { <nl> / / Cleanup the dead blocks from the inlined lazy property getters . <nl> - removeUnreachableBlocks ( * getFunction ( ) ) ; <nl> - <nl> + removeUnreachableBlocks ( * Fn ) ; <nl> invalidateAnalysis ( SILAnalysis : : InvalidationKind : : Everything ) ; <nl> } else if ( Changed ) { <nl> invalidateAnalysis ( SILAnalysis : : InvalidationKind : : CallsAndInstructions ) ; <nl> mmm a / lib / SILOptimizer / Utils / OwnershipOptUtils . cpp <nl> ppp b / lib / SILOptimizer / Utils / OwnershipOptUtils . cpp <nl> SILBasicBlock : : iterator OwnershipRAUWUtility : : perform ( ) { <nl> / / Top level entry points to RAUW code . <nl> / / <nl> bool OwnershipFixupContext : : canFixUpOwnershipForRAUW ( <nl> - SingleValueInstruction * oldValue , SILValue newValue ) { <nl> + const SingleValueInstruction * oldValue , SILValue newValue ) { <nl> auto newOwnershipKind = newValue . getOwnershipKind ( ) ; <nl> <nl> / / If our new kind is ValueOwnershipKind : : None , then we are fine . We <nl> new file mode 100644 <nl> index 000000000000 . . 3713a2432818 <nl> mmm / dev / null <nl> ppp b / test / SILOptimizer / cse_apply_ossa . sil <nl> <nl> + / / RUN : % target - sil - opt - enable - sil - verify - all % s - cse | % FileCheck % s <nl> + <nl> + sil_stage canonical <nl> + <nl> + import Builtin <nl> + import Swift <nl> + <nl> + / / " return ( x + y ) + ( x + y ) " <nl> + / / make sure we are only calculating x + y once . <nl> + <nl> + / / CHECK - LABEL : simply_arith : <nl> + / / CHECK : builtin <nl> + / / CHECK : cond_fail <nl> + / / CHECK : builtin <nl> + / / CHECK : cond_fail <nl> + / / CHECK - NOT : builtin <nl> + / / CHECK - NOT : cond_fail <nl> + / / CHECK - LABEL : } / / end sil function ' simply_arith ' <nl> + sil [ ossa ] @ simply_arith : $ @ convention ( thin ) ( Int32 , Int32 ) - > Int32 { <nl> + bb0 ( % 0 : $ Int32 , % 1 : $ Int32 ) : <nl> + debug_value % 0 : $ Int32 , let , name " x " <nl> + debug_value % 1 : $ Int32 , let , name " y " <nl> + % 5 = struct_extract % 0 : $ Int32 , # Int32 . _value <nl> + % 6 = struct_extract % 1 : $ Int32 , # Int32 . _value <nl> + % 7 = integer_literal $ Builtin . Int1 , - 1 <nl> + % 8 = builtin " sadd_with_overflow_Int32 " ( % 5 : $ Builtin . Int32 , % 6 : $ Builtin . Int32 , % 7 : $ Builtin . Int1 ) : $ ( Builtin . Int32 , Builtin . Int1 ) <nl> + % 9 = tuple_extract % 8 : $ ( Builtin . Int32 , Builtin . Int1 ) , 0 <nl> + % 10 = tuple_extract % 8 : $ ( Builtin . Int32 , Builtin . Int1 ) , 1 <nl> + cond_fail % 10 : $ Builtin . Int1 <nl> + % 12 = struct $ Int32 ( % 9 : $ Builtin . Int32 ) <nl> + % 14 = struct_extract % 0 : $ Int32 , # Int32 . _value <nl> + % 15 = struct_extract % 1 : $ Int32 , # Int32 . _value <nl> + % 16 = integer_literal $ Builtin . Int1 , - 1 <nl> + % 17 = builtin " sadd_with_overflow_Int32 " ( % 14 : $ Builtin . Int32 , % 15 : $ Builtin . Int32 , % 16 : $ Builtin . Int1 ) : $ ( Builtin . Int32 , Builtin . Int1 ) <nl> + % 18 = tuple_extract % 17 : $ ( Builtin . Int32 , Builtin . Int1 ) , 0 <nl> + % 19 = tuple_extract % 17 : $ ( Builtin . Int32 , Builtin . Int1 ) , 1 <nl> + cond_fail % 19 : $ Builtin . Int1 <nl> + % 21 = struct $ Int32 ( % 18 : $ Builtin . Int32 ) <nl> + % 23 = struct_extract % 12 : $ Int32 , # Int32 . _value <nl> + % 24 = struct_extract % 21 : $ Int32 , # Int32 . _value <nl> + % 25 = integer_literal $ Builtin . Int1 , - 1 <nl> + % 26 = builtin " sadd_with_overflow_Int32 " ( % 23 : $ Builtin . Int32 , % 24 : $ Builtin . Int32 , % 25 : $ Builtin . Int1 ) : $ ( Builtin . Int32 , Builtin . Int1 ) <nl> + % 27 = tuple_extract % 26 : $ ( Builtin . Int32 , Builtin . Int1 ) , 0 <nl> + % 28 = tuple_extract % 26 : $ ( Builtin . Int32 , Builtin . Int1 ) , 1 <nl> + cond_fail % 28 : $ Builtin . Int1 <nl> + % 30 = struct $ Int32 ( % 27 : $ Builtin . Int32 ) <nl> + return % 30 : $ Int32 <nl> + } <nl> + <nl> + sil [ ossa ] @ readnone : $ @ convention ( thin ) ( Int64 , Int64 ) - > Int64 { <nl> + bb0 ( % 0 : $ Int64 , % 1 : $ Int64 ) : <nl> + return % 0 : $ Int64 <nl> + } <nl> + <nl> + sil_global @ gg : $ Int64 <nl> + <nl> + sil [ ossa ] @ readsome : $ @ convention ( thin ) ( Int64 , Int64 ) - > Int64 { <nl> + bb0 ( % 0 : $ Int64 , % 1 : $ Int64 ) : <nl> + % g = global_addr @ gg : $ * Int64 <nl> + % l = load [ trivial ] % g : $ * Int64 <nl> + return % l : $ Int64 <nl> + } <nl> + <nl> + struct Storage { <nl> + var a : Int64 <nl> + var b : Int64 <nl> + var c : Int64 <nl> + } <nl> + <nl> + class XX { <nl> + } <nl> + <nl> + sil_global @ ggs : $ Storage <nl> + <nl> + sil [ ossa ] @ retain_only : $ @ convention ( thin ) ( ) - > @ owned XX { <nl> + bb0 : <nl> + % g = global_addr @ ggs : $ * Storage <nl> + % a = address_to_pointer % g : $ * Storage to $ Builtin . RawPointer <nl> + % r = raw_pointer_to_ref % a : $ Builtin . RawPointer to $ XX <nl> + % copy = copy_value % r : $ XX <nl> + return % copy : $ XX <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_readnone_apply : <nl> + / / CHECK : [ [ A : % [ 0 - 9 ] + ] ] = apply <nl> + / / CHECK : [ [ S : % [ 0 - 9 ] + ] ] = struct_extract [ [ A ] ] <nl> + / / CHECK : builtin " sadd_with_overflow_Int64 " ( [ [ S ] ] : $ Builtin . Int64 , [ [ S ] ] : $ Builtin . Int64 <nl> + / / CHECK - LABEL : } / / end sil function ' cse_readnone_apply ' <nl> + sil [ ossa ] @ cse_readnone_apply : $ @ convention ( thin ) ( Int64 ) - > Int64 { <nl> + bb0 ( % 0 : $ Int64 ) : <nl> + % 2 = function_ref @ readnone : $ @ convention ( thin ) ( Int64 , Int64 ) - > Int64 <nl> + % 3 = integer_literal $ Builtin . Int64 , 3 <nl> + % 4 = struct $ Int64 ( % 3 : $ Builtin . Int64 ) <nl> + % 5 = apply % 2 ( % 0 , % 4 ) : $ @ convention ( thin ) ( Int64 , Int64 ) - > Int64 <nl> + % 6 = apply % 2 ( % 0 , % 4 ) : $ @ convention ( thin ) ( Int64 , Int64 ) - > Int64 <nl> + % 7 = struct_extract % 5 : $ Int64 , # Int64 . _value <nl> + % 8 = struct_extract % 6 : $ Int64 , # Int64 . _value <nl> + % 9 = integer_literal $ Builtin . Int1 , 0 <nl> + % 10 = builtin " sadd_with_overflow_Int64 " ( % 7 : $ Builtin . Int64 , % 8 : $ Builtin . Int64 , % 9 : $ Builtin . Int1 ) : $ ( Builtin . Int64 , Builtin . Int1 ) <nl> + % 11 = tuple_extract % 10 : $ ( Builtin . Int64 , Builtin . Int1 ) , 0 <nl> + % 14 = struct $ Int64 ( % 11 : $ Builtin . Int64 ) <nl> + return % 14 : $ Int64 <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ dont_cse_readsome_apply : <nl> + / / CHECK : % { { [ 0 - 9 ] + } } = apply <nl> + / / CHECK : % { { [ 0 - 9 ] + } } = apply <nl> + / / CHECK - LABEL : } / / end sil function ' dont_cse_readsome_apply ' <nl> + sil [ ossa ] @ dont_cse_readsome_apply : $ @ convention ( thin ) ( Int64 ) - > Int64 { <nl> + bb0 ( % 0 : $ Int64 ) : <nl> + % 2 = function_ref @ readsome : $ @ convention ( thin ) ( Int64 , Int64 ) - > Int64 <nl> + % 3 = integer_literal $ Builtin . Int64 , 3 <nl> + % 4 = struct $ Int64 ( % 3 : $ Builtin . Int64 ) <nl> + % 5 = apply % 2 ( % 0 , % 4 ) : $ @ convention ( thin ) ( Int64 , Int64 ) - > Int64 <nl> + % 6 = apply % 2 ( % 0 , % 4 ) : $ @ convention ( thin ) ( Int64 , Int64 ) - > Int64 <nl> + % 7 = struct_extract % 5 : $ Int64 , # Int64 . _value <nl> + % 8 = struct_extract % 6 : $ Int64 , # Int64 . _value <nl> + % 9 = integer_literal $ Builtin . Int1 , 0 <nl> + % 10 = builtin " sadd_with_overflow_Int64 " ( % 7 : $ Builtin . Int64 , % 8 : $ Builtin . Int64 , % 9 : $ Builtin . Int1 ) : $ ( Builtin . Int64 , Builtin . Int1 ) <nl> + % 11 = tuple_extract % 10 : $ ( Builtin . Int64 , Builtin . Int1 ) , 0 <nl> + % 14 = struct $ Int64 ( % 11 : $ Builtin . Int64 ) <nl> + return % 14 : $ Int64 <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ dont_cse_retain_only_apply : <nl> + / / CHECK : % { { [ 0 - 9 ] + } } = apply <nl> + / / CHECK : % { { [ 0 - 9 ] + } } = apply <nl> + / / CHECK - LABEL : } / / end sil function ' dont_cse_retain_only_apply ' <nl> + sil [ ossa ] @ dont_cse_retain_only_apply : $ @ convention ( thin ) ( ) - > ( ) { <nl> + bb0 : <nl> + % f = function_ref @ retain_only : $ @ convention ( thin ) ( ) - > @ owned XX <nl> + % a1 = apply % f ( ) : $ @ convention ( thin ) ( ) - > @ owned XX <nl> + % a2 = apply % f ( ) : $ @ convention ( thin ) ( ) - > @ owned XX <nl> + destroy_value % a1 : $ XX <nl> + destroy_value % a2 : $ XX <nl> + % r = tuple ( ) <nl> + return % r : $ ( ) <nl> + } <nl> + <nl> + class Klass { <nl> + } <nl> + <nl> + sil [ ossa ] @ identity_owned : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned Klass { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + return % 0 : $ Klass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ apply_nontrivial_test1 : <nl> + / / CHECK : apply <nl> + / / CHECK - NOT : apply <nl> + / / CHECK - LABEL : } / / end sil function ' apply_nontrivial_test1 ' <nl> + sil [ ossa ] @ apply_nontrivial_test1 : $ @ convention ( thin ) ( @ owned Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % f = function_ref @ identity_owned : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned Klass <nl> + % a1 = apply % f ( % 0 ) : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned Klass <nl> + % a2 = apply % f ( % copy0 ) : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned Klass <nl> + destroy_value % a1 : $ Klass <nl> + destroy_value % a2 : $ Klass <nl> + % r = tuple ( ) <nl> + return % r : $ ( ) <nl> + } <nl> + <nl> + sil [ ossa ] @ identity_guaranteed : $ @ convention ( thin ) ( @ guaranteed Klass ) - > @ owned Klass { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % copy = copy_value % 0 : $ Klass <nl> + return % copy : $ Klass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ apply_nontrivial_test2 : <nl> + / / CHECK : apply <nl> + / / CHECK : apply <nl> + / / CHECK - LABEL : } / / end sil function ' apply_nontrivial_test2 ' <nl> + sil [ ossa ] @ apply_nontrivial_test2 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % f = function_ref @ identity_guaranteed : $ @ convention ( thin ) ( @ guaranteed Klass ) - > @ owned Klass <nl> + % a1 = apply % f ( % 0 ) : $ @ convention ( thin ) ( @ guaranteed Klass ) - > @ owned Klass <nl> + % a2 = apply % f ( % 0 ) : $ @ convention ( thin ) ( @ guaranteed Klass ) - > @ owned Klass <nl> + destroy_value % a1 : $ Klass <nl> + destroy_value % a2 : $ Klass <nl> + % r = tuple ( ) <nl> + return % r : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ apply_nontrivial_test3 : <nl> + / / CHECK : apply <nl> + / / CHECK - NOT : apply <nl> + / / CHECK - LABEL : } / / end sil function ' apply_nontrivial_test3 ' <nl> + sil [ ossa ] @ apply_nontrivial_test3 : $ @ convention ( thin ) ( @ owned Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % f = function_ref @ identity_owned : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned Klass <nl> + % a2 = apply % f ( % copy0 ) : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned Klass <nl> + % a1 = apply % f ( % 0 ) : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned Klass <nl> + destroy_value % a1 : $ Klass <nl> + destroy_value % a2 : $ Klass <nl> + % r = tuple ( ) <nl> + return % r : $ ( ) <nl> + } <nl> new file mode 100644 <nl> index 000000000000 . . 775adad8658d <nl> mmm / dev / null <nl> ppp b / test / SILOptimizer / cse_forwarding_ossa . sil <nl> <nl> + / / RUN : % target - sil - opt - enable - sil - verify - all % s - cse | % FileCheck % s <nl> + sil_stage canonical <nl> + <nl> + import Builtin <nl> + <nl> + class SuperKlass { } <nl> + <nl> + class Klass : SuperKlass { } <nl> + <nl> + struct NonTrivialStruct { <nl> + var val : Klass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast1 : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast1 ' <nl> + sil [ ossa ] @ cse_copy_upcast1 : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned ( SuperKlass , SuperKlass ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = upcast % 0 : $ Klass to $ SuperKlass <nl> + % 2 = upcast % copy0 : $ Klass to $ SuperKlass <nl> + % res = tuple ( % 1 : $ SuperKlass , % 2 : $ SuperKlass ) <nl> + return % res : $ ( SuperKlass , SuperKlass ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast2 : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast2 ' <nl> + sil [ ossa ] @ cse_copy_upcast2 : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned ( SuperKlass , SuperKlass ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = upcast % copy0 : $ Klass to $ SuperKlass <nl> + % 2 = upcast % 0 : $ Klass to $ SuperKlass <nl> + % res = tuple ( % 1 : $ SuperKlass , % 2 : $ SuperKlass ) <nl> + return % res : $ ( SuperKlass , SuperKlass ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast3 : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast3 ' <nl> + sil [ ossa ] @ cse_copy_upcast3 : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned ( SuperKlass , SuperKlass ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % copy1 = copy_value % 0 : $ Klass <nl> + % 1 = upcast % copy0 : $ Klass to $ SuperKlass <nl> + % 2 = upcast % copy1 : $ Klass to $ SuperKlass <nl> + destroy_value % 0 : $ Klass <nl> + % res = tuple ( % 1 : $ SuperKlass , % 2 : $ SuperKlass ) <nl> + return % res : $ ( SuperKlass , SuperKlass ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast4 : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast4 ' <nl> + sil [ ossa ] @ cse_copy_upcast4 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > @ owned SuperKlass { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = upcast % 0 : $ Klass to $ SuperKlass <nl> + % 2 = upcast % copy0 : $ Klass to $ SuperKlass <nl> + destroy_value % 2 : $ SuperKlass <nl> + % copy1 = copy_value % 1 : $ SuperKlass <nl> + return % copy1 : $ SuperKlass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast5 : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast5 ' <nl> + sil [ ossa ] @ cse_copy_upcast5 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > @ owned SuperKlass { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = upcast % copy0 : $ Klass to $ SuperKlass <nl> + % 2 = upcast % 0 : $ Klass to $ SuperKlass <nl> + destroy_value % 1 : $ SuperKlass <nl> + % copy2 = copy_value % 2 : $ SuperKlass <nl> + return % copy2 : $ SuperKlass <nl> + } <nl> + <nl> + sil [ ossa ] @ useSuperKlass1 : $ @ convention ( thin ) ( @ guaranteed SuperKlass ) - > ( ) <nl> + sil [ ossa ] @ useSuperKlass2 : $ @ convention ( thin ) ( @ owned SuperKlass ) - > ( ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast6 : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast6 ' <nl> + sil [ ossa ] @ cse_copy_upcast6 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > @ owned SuperKlass { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % 1 = upcast % 0 : $ Klass to $ SuperKlass <nl> + % func = function_ref @ useSuperKlass1 : $ @ convention ( thin ) ( @ guaranteed SuperKlass ) - > ( ) <nl> + apply % func ( % 1 ) : $ @ convention ( thin ) ( @ guaranteed SuperKlass ) - > ( ) <nl> + % 2 = upcast % 0 : $ Klass to $ SuperKlass <nl> + % copy2 = copy_value % 2 : $ SuperKlass <nl> + return % copy2 : $ SuperKlass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast7 : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast7 ' <nl> + sil [ ossa ] @ cse_copy_upcast7 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = upcast % copy0 : $ Klass to $ SuperKlass <nl> + % 2 = upcast % 0 : $ Klass to $ SuperKlass <nl> + cond_br undef , bb1 , bb2 <nl> + <nl> + bb1 : <nl> + br bb3 <nl> + <nl> + bb2 : <nl> + % copy2 = copy_value % 2 : $ SuperKlass <nl> + % func = function_ref @ useSuperKlass2 : $ @ convention ( thin ) ( @ owned SuperKlass ) - > ( ) <nl> + apply % func ( % copy2 ) : $ @ convention ( thin ) ( @ owned SuperKlass ) - > ( ) <nl> + br bb3 <nl> + <nl> + bb3 : <nl> + destroy_value % 1 : $ SuperKlass <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast8 : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast8 ' <nl> + sil [ ossa ] @ cse_copy_upcast8 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > @ owned SuperKlass { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % borrow0 = begin_borrow % copy0 : $ Klass <nl> + % 1 = upcast % borrow0 : $ Klass to $ SuperKlass <nl> + end_borrow % borrow0 : $ Klass <nl> + destroy_value % copy0 : $ Klass <nl> + % 2 = upcast % 0 : $ Klass to $ SuperKlass <nl> + % copy2 = copy_value % 2 : $ SuperKlass <nl> + return % copy2 : $ SuperKlass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_unchecked_ref_cast : <nl> + / / CHECK : unchecked_ref_cast <nl> + / / CHECK - NOT : unchecked_ref_cast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_unchecked_ref_cast ' <nl> + sil [ ossa ] @ cse_copy_unchecked_ref_cast : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned ( SuperKlass , SuperKlass ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = unchecked_ref_cast % 0 : $ Klass to $ SuperKlass <nl> + % 2 = unchecked_ref_cast % copy0 : $ Klass to $ SuperKlass <nl> + % res = tuple ( % 1 : $ SuperKlass , % 2 : $ SuperKlass ) <nl> + return % res : $ ( SuperKlass , SuperKlass ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast_destroy_before_common_expr : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast_destroy_before_common_expr ' <nl> + sil [ ossa ] @ cse_copy_upcast_destroy_before_common_expr : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned SuperKlass { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = upcast % 0 : $ Klass to $ SuperKlass <nl> + destroy_value % 1 : $ SuperKlass <nl> + % 2 = upcast % copy0 : $ Klass to $ SuperKlass <nl> + return % 2 : $ SuperKlass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast_need_destroys : <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast_need_destroys ' <nl> + sil [ ossa ] @ cse_copy_upcast_need_destroys : $ @ convention ( thin ) ( @ owned Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = upcast % 0 : $ Klass to $ SuperKlass <nl> + destroy_value % 1 : $ SuperKlass <nl> + cond_br undef , bb1 , bb2 <nl> + <nl> + bb1 : <nl> + % 2 = upcast % copy0 : $ Klass to $ SuperKlass <nl> + destroy_value % 2 : $ SuperKlass <nl> + br bb3 <nl> + <nl> + bb2 : <nl> + destroy_value % copy0 : $ Klass <nl> + br bb3 <nl> + <nl> + bb3 : <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_copy_upcast_multiple_identity : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_copy_upcast_multiple_identity ' <nl> + sil [ ossa ] @ cse_copy_upcast_multiple_identity : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned SuperKlass { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % copy00 = copy_value % copy0 : $ Klass <nl> + % 1 = upcast % 0 : $ Klass to $ SuperKlass <nl> + destroy_value % 1 : $ SuperKlass <nl> + % 2 = upcast % copy00 : $ Klass to $ SuperKlass <nl> + destroy_value % copy0 : $ Klass <nl> + return % 2 : $ SuperKlass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_borrow_upcast : <nl> + / / CHECK : upcast <nl> + / / CHECK - NOT : upcast <nl> + / / CHECK - LABEL : } / / end sil function ' cse_borrow_upcast ' <nl> + sil [ ossa ] @ cse_borrow_upcast : $ @ convention ( thin ) ( @ owned Klass ) - > @ owned ( SuperKlass , SuperKlass ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % borrow = begin_borrow % 0 : $ Klass <nl> + % copy0_1 = copy_value % borrow : $ Klass <nl> + % copy0_2 = copy_value % borrow : $ Klass <nl> + % 1 = upcast % copy0_1 : $ Klass to $ SuperKlass <nl> + % 2 = upcast % copy0_2 : $ Klass to $ SuperKlass <nl> + end_borrow % borrow : $ Klass <nl> + destroy_value % 0 : $ Klass <nl> + % res = tuple ( % 1 : $ SuperKlass , % 2 : $ SuperKlass ) <nl> + return % res : $ ( SuperKlass , SuperKlass ) <nl> + } <nl> + <nl> new file mode 100644 <nl> index 000000000000 . . b95fe7230ed3 <nl> mmm / dev / null <nl> ppp b / test / SILOptimizer / cse_objc_ossa . sil <nl> <nl> + / / RUN : % target - sil - opt - enable - sil - verify - all % s - cse | % FileCheck % s <nl> + / / REQUIRES : objc_interop <nl> + sil_stage canonical <nl> + <nl> + import Builtin <nl> + import Swift <nl> + import Foundation <nl> + <nl> + @ objc ( XX ) protocol XX { <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_objc_protocol : <nl> + / / CHECK : objc_protocol # XX : $ Protocol <nl> + / / CHECK - NOT : objc_protocol <nl> + / / CHECK : tuple ( % 0 : $ Protocol , % 0 : $ Protocol ) <nl> + / / CHECK - LABEL : } / / end sil function ' cse_objc_protocol ' <nl> + sil [ ossa ] @ cse_objc_protocol : $ @ convention ( thin ) ( ) - > ( Protocol , Protocol ) { <nl> + bb0 : <nl> + % 0 = objc_protocol # XX : $ Protocol <nl> + % 1 = objc_protocol # XX : $ Protocol <nl> + % 2 = tuple ( % 0 : $ Protocol , % 1 : $ Protocol ) <nl> + return % 2 : $ ( Protocol , Protocol ) <nl> + } <nl> + <nl> + @ objc protocol Walkable { <nl> + func walk ( ) <nl> + } <nl> + <nl> + class Bar : NSObject , Walkable { <nl> + override init ( ) <nl> + func walk ( ) <nl> + deinit <nl> + } <nl> + <nl> + func trytowalk ( f : Walkable ) <nl> + <nl> + / / test . Bar . init ( test . Bar . Type ) ( ) - > test . Bar <nl> + sil hidden [ ossa ] @ _TFC4test3BarcfMS0_FT_S0_ : $ @ convention ( method ) ( @ owned Bar ) - > @ owned Bar { <nl> + bb0 ( % 0 : @ owned $ Bar ) : <nl> + % 1 = alloc_stack $ Bar , let , name " sf " <nl> + % copy1 = copy_value % 0 : $ Bar <nl> + % copy2 = copy_value % 0 : $ Bar <nl> + store % 0 to [ init ] % 1 : $ * Bar <nl> + % 3 = upcast % copy1 : $ Bar to $ NSObject <nl> + % 4 = objc_super_method % copy2 : $ Bar , # NSObject . init ! initializer . foreign : ( NSObject . Type ) - > ( ) - > NSObject , $ @ convention ( objc_method ) ( @ owned NSObject ) - > @ owned NSObject <nl> + % 7 = apply % 4 ( % 3 ) : $ @ convention ( objc_method ) ( @ owned NSObject ) - > @ owned NSObject <nl> + % 8 = unchecked_ref_cast % 7 : $ NSObject to $ Bar <nl> + destroy_value % copy2 : $ Bar <nl> + destroy_addr % 1 : $ * Bar <nl> + dealloc_stack % 1 : $ * Bar <nl> + return % 8 : $ Bar <nl> + } <nl> + <nl> + / / test . Bar . __allocating_init ( test . Bar . Type ) ( ) - > test . Bar <nl> + sil hidden [ ossa ] @ _TFC4test3BarCfMS0_FT_S0_ : $ @ convention ( thin ) ( @ thick Bar . Type ) - > @ owned Bar { <nl> + bb0 ( % 0 : $ @ thick Bar . Type ) : <nl> + % 1 = alloc_ref [ objc ] $ Bar <nl> + / / function_ref test . Bar . init ( test . Bar . Type ) ( ) - > test . Bar <nl> + % 2 = function_ref @ _TFC4test3BarcfMS0_FT_S0_ : $ @ convention ( method ) ( @ owned Bar ) - > @ owned Bar <nl> + % 3 = apply % 2 ( % 1 ) : $ @ convention ( method ) ( @ owned Bar ) - > @ owned Bar <nl> + return % 3 : $ Bar <nl> + } <nl> + <nl> + / / @ objc test . Bar . init ( test . Bar . Type ) ( ) - > test . Bar <nl> + sil hidden [ ossa ] @ _TToFC4test3BarcfMS0_FT_S0_ : $ @ convention ( objc_method ) ( @ owned Bar ) - > @ owned Bar { <nl> + bb0 ( % 0 : @ owned $ Bar ) : <nl> + / / function_ref test . Bar . init ( test . Bar . Type ) ( ) - > test . Bar <nl> + % 1 = function_ref @ _TFC4test3BarcfMS0_FT_S0_ : $ @ convention ( method ) ( @ owned Bar ) - > @ owned Bar <nl> + % 2 = apply % 1 ( % 0 ) : $ @ convention ( method ) ( @ owned Bar ) - > @ owned Bar <nl> + return % 2 : $ Bar <nl> + } <nl> + <nl> + / / test . Bar . walk ( test . Bar ) ( ) - > ( ) <nl> + sil hidden [ ossa ] @ _TFC4test3Bar4walkfS0_FT_T_ : $ @ convention ( method ) ( @ guaranteed Bar ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ Bar ) : <nl> + debug_value % 0 : $ Bar , let , name " self " <nl> + % 2 = tuple ( ) <nl> + return % 2 : $ ( ) <nl> + } <nl> + <nl> + / / test . Bar . __deallocating_deinit <nl> + sil hidden [ ossa ] @ _TFC4test3BarD : $ @ convention ( method ) ( @ owned Bar ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ Bar ) : <nl> + debug_value % 0 : $ Bar , let , name " self " <nl> + % 2 = objc_super_method % 0 : $ Bar , # NSObject . deinit ! deallocator . foreign : ( NSObject ) - > ( ) - > ( ) , $ @ convention ( objc_method ) ( NSObject ) - > ( ) <nl> + % 3 = upcast % 0 : $ Bar to $ NSObject <nl> + % 4 = apply % 2 ( % 3 ) : $ @ convention ( objc_method ) ( NSObject ) - > ( ) <nl> + destroy_value % 3 : $ NSObject <nl> + % 5 = tuple ( ) <nl> + return % 5 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil hidden [ ossa ] @ _TF4test9trytowalkFPS_8Walkable_T_ : <nl> + / / CHECK : bb0 ( % 0 : @ owned $ Walkable ) : <nl> + / / CHECK - NEXT : { { % . * } } = open_existential_ref <nl> + / / CHECK - NEXT : { { % . * } } = objc_method <nl> + / / CHECK - NEXT : { { % . * } } = apply <nl> + / / CHECK - NEXT : { { % . * } } = objc_method <nl> + / / CHECK - NEXT : { { % . * } } = apply <nl> + / / CHECK - NEXT : destroy_value <nl> + / / CHECK - NEXT : { { % . * } } = tuple <nl> + / / test . trytowalk ( test . Walkable ) - > ( ) <nl> + / / CHECK - LABEL : } / / end sil function ' _TF4test9trytowalkFPS_8Walkable_T_ ' <nl> + sil hidden [ ossa ] @ _TF4test9trytowalkFPS_8Walkable_T_ : $ @ convention ( thin ) ( @ owned Walkable ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ Walkable ) : <nl> + % 2 = open_existential_ref % 0 : $ Walkable to $ @ opened ( " 7813D5BE - 4C48 - 11E5 - BD72 - AC87A3294C0A " ) Walkable <nl> + % 3 = objc_method % 2 : $ @ opened ( " 7813D5BE - 4C48 - 11E5 - BD72 - AC87A3294C0A " ) Walkable , # Walkable . walk ! foreign , $ @ convention ( objc_method ) < τ_0_0 where τ_0_0 : Walkable > ( τ_0_0 ) - > ( ) <nl> + % 4 = apply % 3 < @ opened ( " 7813D5BE - 4C48 - 11E5 - BD72 - AC87A3294C0A " ) Walkable > ( % 2 ) : $ @ convention ( objc_method ) < τ_0_0 where τ_0_0 : Walkable > ( τ_0_0 ) - > ( ) <nl> + % 5 = objc_method % 2 : $ @ opened ( " 7813D5BE - 4C48 - 11E5 - BD72 - AC87A3294C0A " ) Walkable , # Walkable . walk ! foreign , $ @ convention ( objc_method ) < τ_0_0 where τ_0_0 : Walkable > ( τ_0_0 ) - > ( ) <nl> + % 6 = apply % 5 < @ opened ( " 7813D5BE - 4C48 - 11E5 - BD72 - AC87A3294C0A " ) Walkable > ( % 2 ) : $ @ convention ( objc_method ) < τ_0_0 where τ_0_0 : Walkable > ( τ_0_0 ) - > ( ) <nl> + destroy_value % 2 : $ @ opened ( " 7813D5BE - 4C48 - 11E5 - BD72 - AC87A3294C0A " ) Walkable <nl> + % 9 = tuple ( ) <nl> + return % 9 : $ ( ) <nl> + } <nl> + <nl> + / / TODO : open_existential_ref is not handled in OSSA currently <nl> + / / This is because it is not trivial to ownership rauw copy_value users of a redundant open_existential_ref . <nl> + / / Suppose we have an ` open_existential_ref ` and we are trying to replace it with another ` open_existential_ref ` with different type . <nl> + / / If one of the users of the old ` open_existential_ref ` is a ` copy_value ` , we cannot just replace the use . <nl> + / / Because ` copy_value ` ' s result type will be referring to the old type as well . So we have to clone it in order to fix the type after rauw . <nl> + / / <nl> + / / In all other places in the compiler where such rauw needs to be handled , a remapping type is initialized and cloning the instruction before providing to the rauw would fix the type issue . <nl> + / / But since copy_value does not have type dependent operands , we cannot handle it in a similar way . <nl> + / / <nl> + / / This is currently a TODO until we can implement a clean way to fix this issue before calling into ownership rauw . <nl> + <nl> + / / Check that the open_existential_ref is CSEed not only in instructions , but also in the types <nl> + / / of BB arguments . The type of BB2 argument should use the same opened existential as the <nl> + / / one opened in the entry block . <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_open_existential_in_bbarg1 : $ @ convention ( thin ) ( @ owned AnyObject ) - > ( ) <nl> + / / TODOCHECK : open_existential_ref % 0 : $ AnyObject to $ [ [ OPENED : @ opened \ ( . * \ ) AnyObject ] ] <nl> + / / TODOCHECK : bb1 ( % { { [ 0 - 9 ] * } } : $ @ convention ( objc_method ) ( [ [ OPENED ] ] ) - > @ autoreleased Optional < NSString > ) : <nl> + / / TODOCHECK - NOT : open_existential_ref <nl> + / / TODOCHECK : bb3 ( % { { [ 0 - 9 ] * } } : $ @ convention ( objc_method ) ( [ [ OPENED ] ] ) - > @ autoreleased Optional < NSString > ) : <nl> + / / TODOCHECK - NOT : open_existential_ref <nl> + / / CHECK - LABEL : } / / end sil function ' cse_open_existential_in_bbarg1 ' <nl> + sil [ ossa ] @ cse_open_existential_in_bbarg1 : $ @ convention ( thin ) ( @ owned AnyObject ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ AnyObject ) : <nl> + % copy0 = copy_value % 0 : $ AnyObject <nl> + % 1 = open_existential_ref % 0 : $ AnyObject to $ @ opened ( " CCEAC0E2 - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + dynamic_method_br % 1 : $ @ opened ( " CCEAC0E2 - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject , # NSProxy . description ! getter . foreign , bb1 , bb2 <nl> + <nl> + bb1 ( % 3 : $ @ convention ( objc_method ) ( @ opened ( " CCEAC0E2 - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject ) - > @ autoreleased Optional < NSString > ) : <nl> + % 5 = partial_apply % 3 ( % 1 ) : $ @ convention ( objc_method ) ( @ opened ( " CCEAC0E2 - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject ) - > @ autoreleased Optional < NSString > <nl> + % 6 = apply % 5 ( ) : $ @ callee_owned ( ) - > @ owned Optional < NSString > <nl> + % 7 = open_existential_ref % copy0 : $ AnyObject to $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + dynamic_method_br % 7 : $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject , # NSProxy . description ! getter . foreign , bb3 , bb4 <nl> + <nl> + bb2 : <nl> + destroy_value % copy0 : $ AnyObject <nl> + destroy_value % 1 : $ @ opened ( " CCEAC0E2 - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + br bb5 <nl> + <nl> + bb3 ( % 9 : $ @ convention ( objc_method ) ( @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject ) - > @ autoreleased Optional < NSString > ) : <nl> + % copy7 = copy_value % 7 : $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + % 10 = partial_apply % 9 ( % copy7 ) : $ @ convention ( objc_method ) ( @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject ) - > @ autoreleased Optional < NSString > <nl> + % 11 = apply % 10 ( ) : $ @ callee_owned ( ) - > @ owned Optional < NSString > <nl> + destroy_value % 6 : $ Optional < NSString > <nl> + destroy_value % 7 : $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + destroy_value % 11 : $ Optional < NSString > <nl> + br bb5 <nl> + <nl> + bb4 : <nl> + destroy_value % 6 : $ Optional < NSString > <nl> + destroy_value % 7 : $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + br bb5 <nl> + <nl> + bb5 : <nl> + % 13 = tuple ( ) <nl> + return % 13 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_open_existential_in_bbarg2 : $ @ convention ( thin ) ( @ owned AnyObject ) - > ( ) <nl> + / / TODOCHECK : open_existential_ref % 0 : <nl> + / / TODOCHECK - NOT : open_existential_ref <nl> + / / CHECK - LABEL : } / / end sil function ' cse_open_existential_in_bbarg2 ' <nl> + sil [ ossa ] @ cse_open_existential_in_bbarg2 : $ @ convention ( thin ) ( @ owned AnyObject ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ AnyObject ) : <nl> + % copy0 = copy_value % 0 : $ AnyObject <nl> + % 1 = open_existential_ref % 0 : $ AnyObject to $ @ opened ( " CCEAC0E2 - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + dynamic_method_br % 1 : $ @ opened ( " CCEAC0E2 - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject , # NSProxy . description ! getter . foreign , bb1 , bb2 <nl> + <nl> + bb1 ( % 3 : $ @ convention ( objc_method ) ( @ opened ( " CCEAC0E2 - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject ) - > @ autoreleased Optional < NSString > ) : <nl> + % 5 = partial_apply % 3 ( % 1 ) : $ @ convention ( objc_method ) ( @ opened ( " CCEAC0E2 - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject ) - > @ autoreleased Optional < NSString > <nl> + % 6 = apply % 5 ( ) : $ @ callee_owned ( ) - > @ owned Optional < NSString > <nl> + % 7 = open_existential_ref % copy0 : $ AnyObject to $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + br bb3 ( % 7 : $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject ) <nl> + <nl> + bb2 : <nl> + destroy_value % copy0 : $ AnyObject <nl> + destroy_value % 1 : $ @ opened ( " CCEAC0E2 - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + br bb5 <nl> + <nl> + bb3 ( % 9 : @ owned $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject ) : <nl> + % copy9 = copy_value % 9 : $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + destroy_value % 6 : $ Optional < NSString > <nl> + destroy_value % 9 : $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + destroy_value % copy9 : $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + br bb5 <nl> + <nl> + bb4 : <nl> + destroy_value % 6 : $ Optional < NSString > <nl> + destroy_value % 7 : $ @ opened ( " CCEDAF1E - 4BB2 - 11E6 - 86F8 - B8E856428C60 " ) AnyObject <nl> + br bb5 <nl> + <nl> + bb5 : <nl> + % 13 = tuple ( ) <nl> + return % 13 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_value_metatype : <nl> + / / CHECK : value_metatype $ @ objc_metatype <nl> + / / CHECK : objc_metatype_to_object <nl> + / / CHECK - NOT : value_metatype $ @ objc_metatype <nl> + / / CHECK : destroy_value <nl> + / / CHECK - LABEL : } / / end sil function ' cse_value_metatype ' <nl> + sil [ ossa ] @ cse_value_metatype : $ @ convention ( thin ) < T where T : AnyObject > ( @ owned T ) - > @ owned ( AnyObject , AnyObject ) { <nl> + bb0 ( % 0 : @ owned $ T ) : <nl> + % 2 = value_metatype $ @ objc_metatype T . Type , % 0 : $ T <nl> + % 4 = objc_metatype_to_object % 2 : $ @ objc_metatype T . Type to $ AnyObject <nl> + % 5 = value_metatype $ @ objc_metatype T . Type , % 0 : $ T <nl> + % 7 = objc_metatype_to_object % 5 : $ @ objc_metatype T . Type to $ AnyObject <nl> + destroy_value % 0 : $ T <nl> + % 9 = tuple ( % 4 : $ AnyObject , % 7 : $ AnyObject ) <nl> + return % 9 : $ ( AnyObject , AnyObject ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_existential_metatype : <nl> + / / CHECK : existential_metatype $ @ objc_metatype <nl> + / / CHECK : objc_existential_metatype_to_object <nl> + / / CHECK - NOT : existential_metatype $ @ objc_metatype <nl> + / / CHECK : destroy_value <nl> + / / CHECK - LABEL : } / / end sil function ' cse_existential_metatype ' <nl> + sil [ ossa ] @ cse_existential_metatype : $ @ convention ( thin ) ( @ owned XX ) - > @ owned ( AnyObject , AnyObject ) { <nl> + bb0 ( % 0 : @ owned $ XX ) : <nl> + % 2 = existential_metatype $ @ objc_metatype XX . Type , % 0 : $ XX <nl> + % 4 = objc_existential_metatype_to_object % 2 : $ @ objc_metatype XX . Type to $ AnyObject <nl> + % 5 = existential_metatype $ @ objc_metatype XX . Type , % 0 : $ XX <nl> + % 6 = objc_existential_metatype_to_object % 5 : $ @ objc_metatype XX . Type to $ AnyObject <nl> + destroy_value % 0 : $ XX <nl> + % 7 = tuple ( % 4 : $ AnyObject , % 6 : $ AnyObject ) <nl> + return % 7 : $ ( AnyObject , AnyObject ) <nl> + } <nl> + <nl> + class B { } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ nocse_existential_metatype_addr : <nl> + / / CHECK : store <nl> + / / CHECK : existential_metatype $ @ thick Any . Type <nl> + / / CHECK : store <nl> + / / CHECK : existential_metatype $ @ thick Any . Type <nl> + / / CHECK - LABEL : } / / end sil function ' nocse_existential_metatype_addr ' <nl> + sil [ ossa ] @ nocse_existential_metatype_addr : $ @ convention ( thin ) ( @ owned B , @ owned B ) - > ( @ thick Any . Type , @ thick Any . Type ) { <nl> + bb0 ( % 0 : @ owned $ B , % 1 : @ owned $ B ) : <nl> + % 2 = alloc_stack $ Any <nl> + % 3 = init_existential_addr % 2 : $ * Any , $ B <nl> + store % 0 to [ init ] % 3 : $ * B <nl> + % 5 = existential_metatype $ @ thick Any . Type , % 2 : $ * Any <nl> + store % 1 to [ assign ] % 3 : $ * B <nl> + % 7 = existential_metatype $ @ thick Any . Type , % 2 : $ * Any <nl> + % 99 = tuple ( % 5 : $ @ thick Any . Type , % 7 : $ @ thick Any . Type ) <nl> + dealloc_stack % 2 : $ * Any <nl> + return % 99 : $ ( @ thick Any . Type , @ thick Any . Type ) <nl> + } <nl> + <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_objc_metatype_to_object : <nl> + / / CHECK : value_metatype $ @ objc_metatype <nl> + / / CHECK : objc_metatype_to_object <nl> + / / CHECK - NOT : value_metatype $ @ objc_metatype <nl> + / / CHECK - NOT : objc_metatype_to_object <nl> + / / CHECK : destroy_value <nl> + / / CHECK - LABEL : } / / end sil function ' cse_objc_metatype_to_object ' <nl> + sil [ ossa ] @ cse_objc_metatype_to_object : $ @ convention ( thin ) < T where T : AnyObject > ( @ owned T ) - > @ owned ( AnyObject , AnyObject ) { <nl> + bb0 ( % 0 : @ owned $ T ) : <nl> + % 2 = value_metatype $ @ objc_metatype T . Type , % 0 : $ T <nl> + % 4 = objc_metatype_to_object % 2 : $ @ objc_metatype T . Type to $ AnyObject <nl> + % 5 = value_metatype $ @ objc_metatype T . Type , % 0 : $ T <nl> + % 7 = objc_metatype_to_object % 5 : $ @ objc_metatype T . Type to $ AnyObject <nl> + destroy_value % 0 : $ T <nl> + % 9 = tuple ( % 4 : $ AnyObject , % 7 : $ AnyObject ) <nl> + return % 9 : $ ( AnyObject , AnyObject ) <nl> + } <nl> + <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_objc_existential_metatype_to_object : <nl> + / / CHECK : existential_metatype $ @ objc_metatype <nl> + / / CHECK : objc_existential_metatype_to_object <nl> + / / CHECK - NOT : existential_metatype $ @ objc_metatype <nl> + / / CHECK - NOT : objc_existential_metatype_to_object <nl> + / / CHECK : destroy_value <nl> + / / CHECK - LABEL : } / / end sil function ' cse_objc_existential_metatype_to_object ' <nl> + sil [ ossa ] @ cse_objc_existential_metatype_to_object : $ @ convention ( thin ) ( @ owned XX ) - > @ owned ( AnyObject , AnyObject ) { <nl> + bb0 ( % 0 : @ owned $ XX ) : <nl> + % 2 = existential_metatype $ @ objc_metatype XX . Type , % 0 : $ XX <nl> + % 4 = objc_existential_metatype_to_object % 2 : $ @ objc_metatype XX . Type to $ AnyObject <nl> + % 5 = existential_metatype $ @ objc_metatype XX . Type , % 0 : $ XX <nl> + % 6 = objc_existential_metatype_to_object % 5 : $ @ objc_metatype XX . Type to $ AnyObject <nl> + destroy_value % 0 : $ XX <nl> + % 7 = tuple ( % 4 : $ AnyObject , % 6 : $ AnyObject ) <nl> + return % 7 : $ ( AnyObject , AnyObject ) <nl> + } <nl> + <nl> + @ objc <nl> + class XXX { <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_objc_to_thick_metatype : <nl> + / / CHECK : objc_to_thick_metatype <nl> + / / CHECK - NOT : objc_to_thick_metatype <nl> + / / CHECK : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' cse_objc_to_thick_metatype ' <nl> + sil [ ossa ] @ cse_objc_to_thick_metatype : $ @ convention ( thin ) ( @ objc_metatype XXX . Type ) - > ( @ thick XXX . Type , @ thick XXX . Type ) { <nl> + bb0 ( % 0 : $ @ objc_metatype XXX . Type ) : <nl> + % 1 = objc_to_thick_metatype % 0 : $ @ objc_metatype XXX . Type to $ @ thick XXX . Type <nl> + % 2 = objc_to_thick_metatype % 0 : $ @ objc_metatype XXX . Type to $ @ thick XXX . Type <nl> + % 3 = tuple ( % 1 : $ @ thick XXX . Type , % 2 : $ @ thick XXX . Type ) <nl> + return % 3 : $ ( @ thick XXX . Type , @ thick XXX . Type ) <nl> + } <nl> + <nl> + sil_vtable Bar { <nl> + # Bar . init ! initializer : @ _TFC4test3BarcfMS0_FT_S0_ / / test . Bar . init ( test . Bar . Type ) ( ) - > test . Bar <nl> + # Bar . walk : @ _TFC4test3Bar4walkfS0_FT_T_ / / test . Bar . walk ( test . Bar ) ( ) - > ( ) <nl> + # Bar . deinit ! deallocator : @ _TFC4test3BarD / / test . Bar . __deallocating_deinit <nl> + } <nl> + <nl> new file mode 100644 <nl> index 000000000000 . . 55a3fb509f91 <nl> mmm / dev / null <nl> ppp b / test / SILOptimizer / cse_ossa . sil <nl> <nl> + / / RUN : % target - sil - opt - enable - sil - verify - all % s - cse | % FileCheck % s <nl> + sil_stage canonical <nl> + <nl> + import Builtin <nl> + import Swift <nl> + <nl> + class B { } <nl> + class E : B { } <nl> + <nl> + class C { } <nl> + class D : C { } <nl> + <nl> + class Ping { <nl> + func ping ( ) - > Ping <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / <nl> + / / Simple DCE Tests / / <nl> + / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ dead_inst_elimination_one_bb : <nl> + / / CHECK - NOT : integer_literal $ Builtin . Int64 , 24 <nl> + / / CHECK - LABEL : } / / end sil function ' dead_inst_elimination_one_bb ' <nl> + sil [ ossa ] @ dead_inst_elimination_one_bb : $ @ convention ( thin ) ( ) - > ( ) { <nl> + % 0 = integer_literal $ Builtin . Int64 , 24 <nl> + % 1 = tuple ( ) <nl> + return % 1 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ dead_inst_elimination_diamond : <nl> + / / CHECK : bb0 <nl> + / / CHECK - NOT : integer_literal $ Builtin . Int64 , 24 <nl> + / / CHECK : bb1 <nl> + / / CHECK - NOT : integer_literal $ Builtin . Int64 , 48 <nl> + / / CHECK - LABEL : } / / end sil function ' dead_inst_elimination_diamond ' <nl> + sil [ ossa ] @ dead_inst_elimination_diamond : $ @ convention ( thin ) ( Builtin . Int1 ) - > ( ) { <nl> + bb0 ( % 0 : $ Builtin . Int1 ) : <nl> + % 1 = integer_literal $ Builtin . Int64 , 24 <nl> + cond_br % 0 , bb1 , bb2 <nl> + <nl> + bb1 : <nl> + % 2 = integer_literal $ Builtin . Int64 , 48 <nl> + br bb3 <nl> + <nl> + bb2 : <nl> + % 3 = integer_literal $ Builtin . Int64 , 96 <nl> + br bb3 <nl> + <nl> + bb3 : <nl> + % 4 = tuple ( ) <nl> + return % 4 : $ ( ) <nl> + } <nl> + <nl> + sil [ ossa ] @ random_counter : $ @ convention ( thin ) ( ) - > Builtin . Int1 <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ dead_inst_elimination_loop : <nl> + / / CHECK : bb0 <nl> + / / CHECK - NOT : integer_literal <nl> + / / CHECK : bb1 <nl> + / / CHECK : function_ref <nl> + / / CHECK : apply <nl> + / / CHECK - NOT : integer_literal <nl> + / / CHECK : bb2 <nl> + / / CHECK - NOT : integer_literal <nl> + / / CHECK : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' dead_inst_elimination_loop ' <nl> + sil [ ossa ] @ dead_inst_elimination_loop : $ @ convention ( thin ) ( ) - > ( ) { <nl> + bb0 : <nl> + % 1 = integer_literal $ Builtin . Int64 , 24 <nl> + br bb1 <nl> + <nl> + bb1 : <nl> + % 2 = function_ref @ random_counter : $ @ convention ( thin ) ( ) - > Builtin . Int1 <nl> + % 3 = apply % 2 ( ) : $ @ convention ( thin ) ( ) - > Builtin . Int1 <nl> + % 4 = integer_literal $ Builtin . Int64 , 48 <nl> + cond_br % 3 , bb2 , bb3 <nl> + <nl> + bb2 : <nl> + br bb1 <nl> + <nl> + bb3 : <nl> + % 5 = integer_literal $ Builtin . Int64 , 59 <nl> + % 6 = tuple ( ) <nl> + return % 6 : $ ( ) <nl> + } <nl> + <nl> + / / For now until the proper unreachable pruning code is committed for <nl> + / / SILCombine , we should not dce dead instructions in unreachable code . <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ dead_inst_elimination_ignore_unreachable <nl> + / / CHECK : bb0 <nl> + / / CHECK - NOT : integer_literal $ Builtin . Int64 , 24 <nl> + / / CHECK : bb1 <nl> + / / CHECK : integer_literal $ Builtin . Int64 , 48 <nl> + / / CHECK - LABEL : } / / end sil function ' dead_inst_elimination_ignore_unreachable ' <nl> + sil [ ossa ] @ dead_inst_elimination_ignore_unreachable : $ @ convention ( thin ) ( ) - > ( ) { <nl> + bb0 : <nl> + % 0 = integer_literal $ Builtin . Int64 , 24 <nl> + br bb2 <nl> + <nl> + bb1 : <nl> + % 1 = integer_literal $ Builtin . Int64 , 48 <nl> + br bb2 <nl> + <nl> + bb2 : <nl> + % 2 = tuple ( ) <nl> + return % 2 : $ ( ) <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + / / Other DCE Tests taken from diagnose_unreachable . sil / / <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + sil [ ossa ] @ exit : $ @ convention ( thin ) ( ) - > Never { <nl> + bb0 : <nl> + br bb1 <nl> + <nl> + bb1 : <nl> + br bb1 <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ removeTriviallyDeadInstructions : <nl> + / / CHECK : store <nl> + / / CHECK : unchecked_ref_cast <nl> + / / CHECK - NOT : unchecked_bitwise_cast <nl> + / / CHECK : } / / end sil function ' removeTriviallyDeadInstructions ' <nl> + sil [ ossa ] @ removeTriviallyDeadInstructions : $ @ convention ( thin ) ( @ owned B ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ B ) : <nl> + % 1 = alloc_box $ < τ_0_0 > { var τ_0_0 } < B > <nl> + % 1a = project_box % 1 : $ < τ_0_0 > { var τ_0_0 } < B > , 0 <nl> + store % 0 to [ init ] % 1a : $ * B <nl> + % 3 = load [ copy ] % 1a : $ * B <nl> + % 5 = unchecked_ref_cast % 3 : $ B to $ Builtin . NativeObject <nl> + destroy_value % 1 : $ < τ_0_0 > { var τ_0_0 } < B > <nl> + % 9 = function_ref @ exit : $ @ convention ( thin ) ( ) - > Never / / ret . exit : ( ) - > ( ) <nl> + % 10 = apply % 9 ( ) : $ @ convention ( thin ) ( ) - > Never <nl> + % 6 = unchecked_bitwise_cast % 5 : $ Builtin . NativeObject to $ B <nl> + destroy_value % 5 : $ Builtin . NativeObject <nl> + % 11 = tuple ( ) <nl> + return % 11 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ removeTriviallyDeadCrossBasicBlocks : <nl> + / / CHECK : cond_br <nl> + / / CHECK - NOT : unchecked_ref_cast <nl> + / / CHECK - LABEL : } / / end sil function ' removeTriviallyDeadCrossBasicBlocks ' <nl> + sil [ ossa ] @ removeTriviallyDeadCrossBasicBlocks : $ @ convention ( thin ) ( @ owned B , Builtin . Int1 ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ B , % 1 : $ Builtin . Int1 ) : <nl> + % 5 = unchecked_ref_cast % 0 : $ B to $ Builtin . NativeObject <nl> + cond_br % 1 , bb1 , bb2 <nl> + bb1 : <nl> + br bb3 <nl> + bb2 : <nl> + br bb3 <nl> + bb3 : <nl> + % 9 = function_ref @ exit : $ @ convention ( thin ) ( ) - > Never / / ret . exit : ( ) - > ( ) <nl> + % 10 = apply % 9 ( ) : $ @ convention ( thin ) ( ) - > Never <nl> + % 21 = unchecked_ref_cast % 5 : $ Builtin . NativeObject to $ B <nl> + destroy_value % 21 : $ B <nl> + % 32 = tuple ( ) <nl> + return % 32 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ dead_use_of_alloc_stack : <nl> + / / CHECK : bb <nl> + / / CHECK : alloc_stack <nl> + / / CHECK : dealloc_stack <nl> + / / CHECK - LABEL : } / / end sil function ' dead_use_of_alloc_stack ' <nl> + sil [ ossa ] @ dead_use_of_alloc_stack : $ @ convention ( thin ) ( ) - > ( ) { <nl> + bb0 : <nl> + % 1 = alloc_stack $ ( ( ) , ( ) , ( ) ) <nl> + % 2 = tuple_element_addr % 1 : $ * ( ( ) , ( ) , ( ) ) , 0 <nl> + dealloc_stack % 1 : $ * ( ( ) , ( ) , ( ) ) <nl> + % 3 = tuple ( ) <nl> + return % 3 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ tuple_extract : <nl> + / / CHECK : bb <nl> + / / CHECK - LABEL : } / / end sil function ' tuple_extract ' <nl> + sil [ ossa ] @ tuple_extract : $ @ convention ( thin ) ( Int64 ) - > Int64 { <nl> + bb0 ( % 0 : $ Int64 ) : <nl> + % 1 = tuple ( % 0 : $ Int64 , % 0 : $ Int64 ) <nl> + return % 0 : $ Int64 <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ do_not_fold_integer_literal : <nl> + / / CHECK : bb <nl> + / / CHECK : cond_br <nl> + / / CHECK : { { ^ bb } } <nl> + / / CHECK - NEXT : integer_literal <nl> + / / CHECK - NEXT : br bb <nl> + / / CHECK : { { ^ bb } } <nl> + / / CHECK - NEXT : integer_literal <nl> + / / CHECK - NEXT : br bb <nl> + / / CHECK - LABEL : } / / end sil function ' do_not_fold_integer_literal ' <nl> + sil [ ossa ] @ do_not_fold_integer_literal : $ @ convention ( thin ) ( Builtin . Int1 ) - > Builtin . Int1 { <nl> + bb0 ( % 0 : $ Builtin . Int1 ) : <nl> + cond_br % 0 , bb1 , bb3 <nl> + <nl> + bb1 : <nl> + % 1 = integer_literal $ Builtin . Int1 , 0 <nl> + br bb2 ( % 1 : $ Builtin . Int1 ) <nl> + <nl> + bb3 : <nl> + % 2 = integer_literal $ Builtin . Int1 , - 1 <nl> + br bb2 ( % 2 : $ Builtin . Int1 ) <nl> + <nl> + bb2 ( % 3 : $ Builtin . Int1 ) : <nl> + return % 3 : $ Builtin . Int1 <nl> + } <nl> + <nl> + enum BoolLike { case true_ , false_ } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ fold_enum : <nl> + / / CHECK : bb <nl> + / / CHECK : switch_enum <nl> + / / CHECK : { { ^ bb } } <nl> + / / CHECK - NOT : enum <nl> + / / CHECK - NEXT : br bb <nl> + / / CHECK : { { ^ bb } } <nl> + / / CHECK - NOT : enum <nl> + / / CHECK - NEXT : br bb <nl> + / / CHECK - LABEL : } / / end sil function ' fold_enum ' <nl> + sil [ ossa ] @ fold_enum : $ @ convention ( thin ) ( BoolLike ) - > BoolLike { <nl> + bb0 ( % 0 : $ BoolLike ) : <nl> + switch_enum % 0 : $ BoolLike , case # BoolLike . true_ ! enumelt : bb1 , case # BoolLike . false_ ! enumelt : bb2 <nl> + <nl> + bb1 : <nl> + % 1 = enum $ BoolLike , # BoolLike . true_ ! enumelt <nl> + br bb3 ( % 1 : $ BoolLike ) <nl> + <nl> + bb2 : <nl> + % 2 = enum $ BoolLike , # BoolLike . false_ ! enumelt <nl> + br bb3 ( % 2 : $ BoolLike ) <nl> + <nl> + bb3 ( % 3 : $ BoolLike ) : <nl> + return % 3 : $ BoolLike <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ do_not_fold_enum : <nl> + / / CHECK : bb <nl> + / / CHECK : switch_enum <nl> + / / CHECK : { { ^ bb } } <nl> + / / CHECK - NEXT : enum <nl> + / / CHECK - NEXT : br bb <nl> + / / CHECK : { { ^ bb } } <nl> + / / CHECK - NEXT : enum <nl> + / / CHECK - NEXT : br bb <nl> + / / CHECK - LABEL : } / / end sil function ' do_not_fold_enum ' <nl> + sil [ ossa ] @ do_not_fold_enum : $ @ convention ( thin ) ( BoolLike ) - > BoolLike { <nl> + bb0 ( % 0 : $ BoolLike ) : <nl> + switch_enum % 0 : $ BoolLike , case # BoolLike . true_ ! enumelt : bb1 , case # BoolLike . false_ ! enumelt : bb2 <nl> + <nl> + bb1 : <nl> + % 1 = enum $ BoolLike , # BoolLike . false_ ! enumelt <nl> + br bb3 ( % 1 : $ BoolLike ) <nl> + <nl> + bb2 : <nl> + % 2 = enum $ BoolLike , # BoolLike . true_ ! enumelt <nl> + br bb3 ( % 2 : $ BoolLike ) <nl> + <nl> + bb3 ( % 3 : $ BoolLike ) : <nl> + return % 3 : $ BoolLike <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / <nl> + / / CSE Tests / / <nl> + / / / / / / / / / / / / / / / <nl> + <nl> + / / Test simple instruction value numbering and usage of an available value in a single bb . <nl> + / / <nl> + / / Specifically we make sure that we only replace Int8 literals with <nl> + / / Int8 literals with the same value . Anything else is outside of scope for cse . <nl> + / / <nl> + / / CHECK - LABEL : sil [ ossa ] @ test0 : <nl> + / / CHECK : [ [ TARGET : % [ 0 - 9 ] + ] ] = integer_literal $ Builtin . Int8 , 8 <nl> + / / CHECK - NEXT : [ [ DECOY1 : % [ 0 - 9 ] + ] ] = integer_literal $ Builtin . Int16 , 8 <nl> + / / CHECK - NEXT : [ [ DECOY2 : % [ 0 - 9 ] + ] ] = integer_literal $ Builtin . Int8 , 1 <nl> + / / CHECK - NEXT : tuple ( [ [ TARGET ] ] : $ Builtin . Int8 , [ [ TARGET ] ] : $ Builtin . Int8 , [ [ DECOY1 ] ] : $ Builtin . Int16 , [ [ DECOY2 ] ] : $ Builtin . Int8 ) <nl> + / / CHECK - LABEL : } / / end sil function ' test0 ' <nl> + sil [ ossa ] @ test0 : $ @ convention ( thin ) ( ) - > ( Builtin . Int8 , Builtin . Int8 , Builtin . Int16 , <nl> + Builtin . Int8 ) { <nl> + % 0 = integer_literal $ Builtin . Int8 , 8 <nl> + % 1 = integer_literal $ Builtin . Int8 , 8 <nl> + % 2 = integer_literal $ Builtin . Int16 , 8 <nl> + % 3 = integer_literal $ Builtin . Int8 , 1 <nl> + % 4 = tuple ( % 0 : $ Builtin . Int8 , % 1 : $ Builtin . Int8 , % 2 : $ Builtin . Int16 , % 3 : $ Builtin . Int8 ) <nl> + return % 4 : $ ( Builtin . Int8 , Builtin . Int8 , Builtin . Int16 , Builtin . Int8 ) <nl> + } <nl> + <nl> + / / Make sure that we can replace cse values in different basic blocks <nl> + / / assuming nothing has changed . <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ test1 : <nl> + / / CHECK : bb0 <nl> + / / CHECK - NEXT : [ [ TARGET : % [ 0 - 9 ] + ] ] = integer_literal $ Builtin . Int8 , 8 <nl> + / / CHECK - NEXT : cond_br undef , bb1 , bb2 <nl> + / / CHECK : bb1 <nl> + / / CHECK - NEXT : br bb3 ( [ [ TARGET ] ] : $ Builtin . Int8 ) <nl> + / / CHECK : bb2 <nl> + / / CHECK - NEXT : [ [ DECOY : % [ 0 - 9 ] + ] ] = integer_literal $ Builtin . Int8 , 16 <nl> + / / CHECK - NEXT : br bb3 ( [ [ DECOY ] ] : $ Builtin . Int8 ) <nl> + / / CHECK : bb3 ( [ [ PHI : % [ 0 - 9 ] + ] ] : $ Builtin . Int8 ) : <nl> + / / CHECK - NEXT : tuple ( [ [ TARGET ] ] : $ Builtin . Int8 , [ [ PHI ] ] : $ Builtin . Int8 , [ [ TARGET ] ] : $ Builtin . Int8 ) <nl> + / / CHECK - LABEL : } / / end sil function ' test1 ' <nl> + sil [ ossa ] @ test1 : $ @ convention ( thin ) ( ) - > ( Builtin . Int8 , Builtin . Int8 , Builtin . Int8 ) { <nl> + bb0 : <nl> + % 0 = integer_literal $ Builtin . Int8 , 8 <nl> + % 1 = integer_literal $ Builtin . Int8 , 8 <nl> + cond_br undef , bb1 , bb2 <nl> + <nl> + bb1 : <nl> + % 2 = integer_literal $ Builtin . Int8 , 8 <nl> + br bb3 ( % 2 : $ Builtin . Int8 ) <nl> + <nl> + bb2 : <nl> + % 3 = integer_literal $ Builtin . Int8 , 16 <nl> + br bb3 ( % 3 : $ Builtin . Int8 ) <nl> + <nl> + bb3 ( % 4 : $ Builtin . Int8 ) : <nl> + % 5 = tuple ( % 0 : $ Builtin . Int8 , % 4 : $ Builtin . Int8 , % 1 : $ Builtin . Int8 ) <nl> + return % 5 : $ ( Builtin . Int8 , Builtin . Int8 , Builtin . Int8 ) <nl> + } <nl> + <nl> + sil [ ossa ] @ evil : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > ( ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ functionrefinst : <nl> + / / CHECK : bb0 <nl> + / / CHECK : function_ref @ evil : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > ( ) <nl> + / / CHECK - NOT : function_ref @ evil : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > ( ) <nl> + / / CHECK - LABEL : } / / end sil function ' functionrefinst ' <nl> + sil [ ossa ] @ functionrefinst : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > ( ) { <nl> + bb0 ( % 0 : $ * Builtin . Int8 ) : <nl> + % 1 = function_ref @ evil : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > ( ) <nl> + apply % 1 ( % 0 ) : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > ( ) <nl> + % 2 = function_ref @ evil : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > ( ) <nl> + apply % 2 ( % 0 ) : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > ( ) <nl> + % 3 = tuple ( ) <nl> + return % 3 : $ ( ) <nl> + } <nl> + <nl> + sil_global @ global_target : $ Builtin . Int64 <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ globaladdr_inst : <nl> + / / CHECK - NOT : global_addr <nl> + / / CHECK : global_addr @ global_target <nl> + / / CHECK - NOT : global_addr <nl> + / / CHECK - LABEL : } / / end sil function ' globaladdr_inst ' <nl> + sil [ ossa ] @ globaladdr_inst : $ @ convention ( thin ) ( ) - > ( Builtin . Int64 ) { <nl> + % 0 = global_addr @ global_target : $ * Builtin . Int64 <nl> + % 1 = global_addr @ global_target : $ * Builtin . Int64 <nl> + % 2 = load [ trivial ] % 0 : $ * Builtin . Int64 <nl> + % 3 = load [ trivial ] % 1 : $ * Builtin . Int64 <nl> + % 5 = integer_literal $ Builtin . Int1 , 0 <nl> + % 6 = builtin " sadd_with_overflow_Int64 " ( % 2 : $ Builtin . Int64 , % 3 : $ Builtin . Int64 , % 5 : $ Builtin . Int1 ) : $ ( Builtin . Int64 , Builtin . Int1 ) <nl> + % 7 = tuple_extract % 6 : $ ( Builtin . Int64 , Builtin . Int1 ) , 0 <nl> + return % 7 : $ ( Builtin . Int64 ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ floatliteral : <nl> + / / CHECK : float_literal $ Builtin . FPIEEE32 , 0x3F800000 <nl> + / / CHECK - NOT : float_literal $ Builtin . FPIEEE32 , 0x3F800000 <nl> + / / CHECK - LABEL : } / / end sil function ' floatliteral ' <nl> + sil [ ossa ] @ floatliteral : $ @ convention ( thin ) ( ) - > ( Builtin . FPIEEE32 ) { <nl> + % 0 = float_literal $ Builtin . FPIEEE32 , 0x3F800000 <nl> + % 1 = float_literal $ Builtin . FPIEEE32 , 0x3F800000 <nl> + % 4 = builtin " fadd_FPIEEE32 " ( % 0 : $ Builtin . FPIEEE32 , % 1 : $ Builtin . FPIEEE32 ) : $ Builtin . FPIEEE32 <nl> + return % 4 : $ ( Builtin . FPIEEE32 ) <nl> + } <nl> + <nl> + sil [ ossa ] @ string_use : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . Word , Builtin . Int1 , @ thin String . Type , Builtin . RawPointer , Builtin . Word , Builtin . Int1 , @ thin String . Type ) - > ( ) <nl> + <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ stringliteral : <nl> + / / CHECK : [ [ TARGET : % [ 0 - 9 ] + ] ] = string_literal utf8 " First " <nl> + / / CHECK : [ [ LEN : % [ 0 - 9 ] + ] ] = integer_literal $ Builtin . Word , 5 <nl> + / / CHECK : [ [ ASCII : % [ 0 - 9 ] + ] ] = integer_literal $ Builtin . Int1 , - 1 <nl> + / / CHECK - NOT : string_literal " First " <nl> + / / CHECK : apply { { % [ 0 - 9 ] + } } ( [ [ TARGET ] ] , [ [ LEN ] ] , [ [ ASCII ] ] , { { % [ 0 - 9 ] + } } , [ [ TARGET ] ] , [ [ LEN ] ] , [ [ ASCII ] ] , { { % [ 0 - 9 ] + } } ) <nl> + / / CHECK - LABEL : } / / end sil function ' stringliteral ' <nl> + sil [ ossa ] @ stringliteral : $ @ convention ( thin ) ( ) - > ( ) { <nl> + % 0 = string_literal utf8 " First " <nl> + % 1 = string_literal utf8 " First " <nl> + % 2 = metatype $ @ thin String . Type <nl> + % l1 = integer_literal $ Builtin . Word , 5 <nl> + % l2 = integer_literal $ Builtin . Word , 5 <nl> + % a1 = integer_literal $ Builtin . Int1 , 1 <nl> + % a2 = integer_literal $ Builtin . Int1 , 1 <nl> + % 3 = function_ref @ string_use : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . Word , Builtin . Int1 , @ thin String . Type , Builtin . RawPointer , Builtin . Word , Builtin . Int1 , @ thin String . Type ) - > ( ) <nl> + apply % 3 ( % 0 , % l1 , % a1 , % 2 , % 1 , % l2 , % a2 , % 2 ) : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . Word , Builtin . Int1 , @ thin String . Type , Builtin . RawPointer , Builtin . Word , Builtin . Int1 , @ thin String . Type ) - > ( ) <nl> + % 4 = tuple ( ) <nl> + return % 4 : $ ( ) <nl> + } <nl> + <nl> + struct Interval { <nl> + var start : Builtin . Int32 <nl> + var end : Builtin . Int32 <nl> + } <nl> + struct FakeInterval { <nl> + var start : Builtin . Int32 <nl> + var end : Builtin . Int32 <nl> + } <nl> + <nl> + sil @ print_interval : $ @ convention ( thin ) ( Interval ) - > ( ) <nl> + sil @ print_fake_interval : $ @ convention ( thin ) ( FakeInterval ) - > ( ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ structliteral : <nl> + / / CHECK : [ [ TARGET : % [ 0 - 9 ] + ] ] = struct $ Interval ( [ [ IN1 : % [ 0 - 9 ] + ] ] : $ Builtin . Int32 , [ [ IN2 : % [ 0 - 9 ] + ] ] : $ Builtin . Int32 ) <nl> + / / CHECK - NOT : struct $ Interval ( [ [ IN1 ] ] : $ Builtin . Int32 , [ [ IN2 ] ] : $ Builtin . Int32 ) <nl> + / / CHECK : [ [ DECOY : % [ 0 - 9 ] + ] ] = struct $ FakeInterval ( [ [ IN1 ] ] : $ Builtin . Int32 , [ [ IN2 ] ] : $ Builtin . Int32 ) <nl> + / / CHECK : [ [ PRINT_INTERVAL_FUN : % [ 0 - 9 ] + ] ] = function_ref @ print_interval <nl> + / / CHECK : apply [ [ PRINT_INTERVAL_FUN ] ] ( [ [ TARGET ] ] ) <nl> + / / CHECK : apply [ [ PRINT_INTERVAL_FUN ] ] ( [ [ TARGET ] ] ) <nl> + / / CHECK : [ [ PRINT_FAKEINTERVAL_FUN : % [ 0 - 9 ] + ] ] = function_ref @ print_fake_interval <nl> + / / CHECK : apply [ [ PRINT_FAKEINTERVAL_FUN ] ] ( [ [ DECOY ] ] ) <nl> + / / CHECK - LABEL : } / / end sil function ' structliteral ' <nl> + sil [ ossa ] @ structliteral : $ @ convention ( thin ) ( Builtin . Int32 , Builtin . Int32 ) - > ( ) { <nl> + bb0 ( % 0 : $ Builtin . Int32 , % 1 : $ Builtin . Int32 ) : <nl> + % 2 = struct $ Interval ( % 0 : $ Builtin . Int32 , % 1 : $ Builtin . Int32 ) <nl> + % 3 = struct $ Interval ( % 0 : $ Builtin . Int32 , % 1 : $ Builtin . Int32 ) <nl> + % 4 = struct $ FakeInterval ( % 0 : $ Builtin . Int32 , % 1 : $ Builtin . Int32 ) <nl> + % 5 = function_ref @ print_interval : $ @ convention ( thin ) ( Interval ) - > ( ) <nl> + apply % 5 ( % 2 ) : $ @ convention ( thin ) ( Interval ) - > ( ) <nl> + apply % 5 ( % 3 ) : $ @ convention ( thin ) ( Interval ) - > ( ) <nl> + % 6 = function_ref @ print_fake_interval : $ @ convention ( thin ) ( FakeInterval ) - > ( ) <nl> + apply % 6 ( % 4 ) : $ @ convention ( thin ) ( FakeInterval ) - > ( ) <nl> + % 9 = tuple ( ) <nl> + return % 9 : $ ( ) <nl> + } <nl> + <nl> + sil [ ossa ] @ sadd_with_address : $ @ convention ( thin ) ( @ inout Builtin . Int32 , @ inout Builtin . Int32 ) - > ( Builtin . Int32 ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ structelementaddr_test : <nl> + / / CHECK : struct_element_addr { { % [ 0 - 9 ] + } } : $ * Interval , # Interval . start <nl> + / / CHECK - NOT : struct_element_addr { { % [ 0 - 9 ] + } } : $ * Interval , # Interval . start <nl> + / / CHECK - LABEL : } / / end sil function ' structelementaddr_test ' <nl> + sil [ ossa ] @ structelementaddr_test : $ @ convention ( thin ) ( @ inout Interval ) - > ( Builtin . Int32 ) { <nl> + bb0 ( % 0 : $ * Interval ) : <nl> + % 1 = struct_element_addr % 0 : $ * Interval , # Interval . start <nl> + % 2 = struct_element_addr % 0 : $ * Interval , # Interval . start <nl> + % 3 = function_ref @ sadd_with_address : $ @ convention ( thin ) ( @ inout Builtin . Int32 , @ inout Builtin . Int32 ) - > ( Builtin . Int32 ) <nl> + % 4 = apply % 3 ( % 1 , % 2 ) : $ @ convention ( thin ) ( @ inout Builtin . Int32 , @ inout Builtin . Int32 ) - > ( Builtin . Int32 ) <nl> + return % 4 : $ ( Builtin . Int32 ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ project_box_test : <nl> + / / CHECK : project_box % 0 : $ < τ_0_0 > { var τ_0_0 } < Builtin . Int32 > <nl> + / / CHECK - NOT : project_box <nl> + / / CHECK - LABEL : } / / end sil function ' project_box_test ' <nl> + sil [ ossa ] @ project_box_test : $ ( @ owned < τ_0_0 > { var τ_0_0 } < Builtin . Int32 > ) - > Builtin . Int32 { <nl> + bb0 ( % 0 : @ owned $ < τ_0_0 > { var τ_0_0 } < Builtin . Int32 > ) : <nl> + % 1 = project_box % 0 : $ < τ_0_0 > { var τ_0_0 } < Builtin . Int32 > , 0 <nl> + % 2 = project_box % 0 : $ < τ_0_0 > { var τ_0_0 } < Builtin . Int32 > , 0 <nl> + % 3 = function_ref @ sadd_with_address : $ @ convention ( thin ) ( @ inout Builtin . Int32 , @ inout Builtin . Int32 ) - > ( Builtin . Int32 ) <nl> + % 4 = apply % 3 ( % 1 , % 2 ) : $ @ convention ( thin ) ( @ inout Builtin . Int32 , @ inout Builtin . Int32 ) - > ( Builtin . Int32 ) <nl> + destroy_value % 0 : $ < τ_0_0 > { var τ_0_0 } < Builtin . Int32 > <nl> + return % 4 : $ ( Builtin . Int32 ) <nl> + } <nl> + <nl> + sil [ ossa ] @ tuple_function : $ @ convention ( thin ) ( ( Builtin . Int32 , Builtin . Int32 ) , ( Builtin . Int32 , Builtin . Int32 ) ) - > ( Builtin . Int32 ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ tuple_test : <nl> + / / CHECK : tuple ( { { % [ 0 - 9 ] + } } : $ Builtin . Int32 , { { % [ 0 - 9 ] + } } : $ Builtin . Int32 ) <nl> + / / CHECK - NOT : tuple ( { { % [ 0 - 9 ] + } } : $ Builtin . Int32 , { { % [ 0 - 9 ] + } } : $ Builtin . Int32 ) <nl> + / / CHECK - LABEL : } / / end sil function ' tuple_test ' <nl> + sil [ ossa ] @ tuple_test : $ @ convention ( thin ) ( Builtin . Int32 , Builtin . Int32 ) - > ( Builtin . Int32 ) { <nl> + bb0 ( % 0 : $ Builtin . Int32 , % 1 : $ Builtin . Int32 ) : <nl> + % 2 = tuple ( % 0 : $ Builtin . Int32 , % 1 : $ Builtin . Int32 ) <nl> + % 3 = tuple ( % 0 : $ Builtin . Int32 , % 1 : $ Builtin . Int32 ) <nl> + % 4 = function_ref @ tuple_function : $ @ convention ( thin ) ( ( Builtin . Int32 , Builtin . Int32 ) , ( Builtin . Int32 , Builtin . Int32 ) ) - > ( Builtin . Int32 ) <nl> + % 5 = apply % 4 ( % 2 , % 3 ) : $ @ convention ( thin ) ( ( Builtin . Int32 , Builtin . Int32 ) , ( Builtin . Int32 , Builtin . Int32 ) ) - > ( Builtin . Int32 ) <nl> + return % 5 : $ ( Builtin . Int32 ) <nl> + } <nl> + <nl> + sil [ ossa ] @ generate_tuple : $ @ convention ( thin ) ( ) - > ( ( Builtin . Int32 , Builtin . Int32 ) ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ tupleextract_test : <nl> + / / CHECK : tuple_extract { { % [ 0 - 9 ] } } : $ ( Builtin . Int32 , Builtin . Int32 ) , 0 <nl> + / / CHECK - NOT : tuple_extract { { % [ 0 - 9 ] } } : $ ( Builtin . Int32 , Builtin . Int32 ) , 0 <nl> + / / CHECK - LABEL : } / / end sil function ' tupleextract_test ' <nl> + sil [ ossa ] @ tupleextract_test : $ @ convention ( thin ) ( ) - > ( Builtin . Int32 ) { <nl> + % 0 = function_ref @ generate_tuple : $ @ convention ( thin ) ( ) - > ( ( Builtin . Int32 , Builtin . Int32 ) ) <nl> + % 1 = apply % 0 ( ) : $ @ convention ( thin ) ( ) - > ( ( Builtin . Int32 , Builtin . Int32 ) ) <nl> + % 2 = tuple_extract % 1 : $ ( Builtin . Int32 , Builtin . Int32 ) , 0 <nl> + % 3 = tuple_extract % 1 : $ ( Builtin . Int32 , Builtin . Int32 ) , 0 <nl> + % 5 = integer_literal $ Builtin . Int1 , 0 <nl> + % 6 = builtin " sadd_with_overflow_Int32 " ( % 2 : $ Builtin . Int32 , % 3 : $ Builtin . Int32 , % 5 : $ Builtin . Int1 ) : $ ( Builtin . Int32 , Builtin . Int1 ) <nl> + % 7 = tuple_extract % 6 : $ ( Builtin . Int32 , Builtin . Int1 ) , 0 <nl> + return % 7 : $ ( Builtin . Int32 ) <nl> + } <nl> + <nl> + sil [ ossa ] @ init_tuple_addr : $ @ convention ( thin ) ( ) - > @ out ( Builtin . Int32 , Builtin . Int32 ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ tupleelementaddr_test : <nl> + / / CHECK : tuple_element_addr { { % [ 0 - 9 ] } } : $ * ( Builtin . Int32 , Builtin . Int32 ) , 0 <nl> + / / CHECK - NOT : tuple_element_addr { { % [ 0 - 9 ] } } : $ * ( Builtin . Int32 , Builtin . Int32 ) , 0 <nl> + / / CHECK - LABEL : } / / end sil function ' tupleelementaddr_test ' <nl> + sil [ ossa ] @ tupleelementaddr_test : $ @ convention ( thin ) ( ) - > ( Builtin . Int32 ) { <nl> + % 0 = alloc_stack $ ( Builtin . Int32 , Builtin . Int32 ) <nl> + % 1 = function_ref @ init_tuple_addr : $ @ convention ( thin ) ( ) - > ( @ out ( Builtin . Int32 , Builtin . Int32 ) ) <nl> + apply % 1 ( % 0 ) : $ @ convention ( thin ) ( ) - > ( @ out ( Builtin . Int32 , Builtin . Int32 ) ) <nl> + % 2 = tuple_element_addr % 0 : $ * ( Builtin . Int32 , Builtin . Int32 ) , 0 <nl> + % 3 = tuple_element_addr % 0 : $ * ( Builtin . Int32 , Builtin . Int32 ) , 0 <nl> + % 5 = integer_literal $ Builtin . Int1 , 0 <nl> + % 6 = load [ trivial ] % 2 : $ * Builtin . Int32 <nl> + % 7 = load [ trivial ] % 3 : $ * Builtin . Int32 <nl> + % 8 = builtin " sadd_with_overflow_Int32 " ( % 6 : $ Builtin . Int32 , % 7 : $ Builtin . Int32 , % 5 : $ Builtin . Int1 ) : $ ( Builtin . Int32 , Builtin . Int1 ) <nl> + % 9 = tuple_extract % 8 : $ ( Builtin . Int32 , Builtin . Int1 ) , 0 <nl> + dealloc_stack % 0 : $ * ( Builtin . Int32 , Builtin . Int32 ) <nl> + return % 9 : $ ( Builtin . Int32 ) <nl> + } <nl> + <nl> + sil [ ossa ] @ metatype_user : $ @ convention ( thin ) ( @ thin String . Type ) - > ( ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ metatype_test : <nl> + / / CHECK : [ [ TARGET : % [ 0 - 9 ] + ] ] = metatype $ @ thin String . Type <nl> + / / CHECK - NOT : { { % [ 0 - 9 ] + } } = metatype $ @ thin String . Type <nl> + / / CHECK : apply { { % [ 0 - 9 ] + } } ( [ [ TARGET ] ] ) <nl> + / / CHECK : apply { { % [ 0 - 9 ] + } } ( [ [ TARGET ] ] ) <nl> + / / CHECK - LABEL : } / / end sil function ' metatype_test ' <nl> + sil [ ossa ] @ metatype_test : $ @ convention ( thin ) ( ) - > ( ) { <nl> + % 0 = metatype $ @ thin String . Type <nl> + % 1 = metatype $ @ thin String . Type <nl> + % 2 = function_ref @ metatype_user : $ @ convention ( thin ) ( @ thin String . Type ) - > ( ) <nl> + apply % 2 ( % 0 ) : $ @ convention ( thin ) ( @ thin String . Type ) - > ( ) <nl> + apply % 2 ( % 1 ) : $ @ convention ( thin ) ( @ thin String . Type ) - > ( ) <nl> + % 3 = tuple ( ) <nl> + return % 3 : $ ( ) <nl> + } <nl> + <nl> + struct StringData { <nl> + var size : Builtin . Word <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ sil_extract_of_string : <nl> + / / <nl> + / / Make sure we only forward the first field of the string_literal <nl> + / / instead of the whole string literal . Otherwise we run into arity <nl> + / / issues . <nl> + / / CHECK - LABEL : } / / end sil function ' sil_extract_of_string ' <nl> + sil [ ossa ] @ sil_extract_of_string : $ @ convention ( thin ) ( ) - > Builtin . Word { <nl> + % 0 = string_literal utf8 " " <nl> + % l1 = integer_literal $ Builtin . Word , 0 <nl> + % 1 = struct $ StringData ( % l1 : $ Builtin . Word ) <nl> + % 2 = struct_extract % 1 : $ StringData , # StringData . size <nl> + return % 2 : $ Builtin . Word <nl> + } <nl> + <nl> + sil [ ossa ] @ helper : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . RawPointer ) - > Builtin . Word <nl> + sil [ ossa ] @ helper2 : $ @ convention ( thin ) ( UInt8 , UInt8 ) - > Builtin . Word <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ sil_string_different_encodings : <nl> + / / CHECK : [ [ T0 : % . * ] ] = function_ref @ helper <nl> + / / CHECK - NEXT : apply [ [ T0 ] ] ( % 0 , % 1 ) <nl> + / / CHECK - LABEL : } / / end sil function ' sil_string_different_encodings ' <nl> + sil [ ossa ] @ sil_string_different_encodings : $ @ convention ( thin ) ( ) - > Builtin . Word { <nl> + % 0 = string_literal utf8 " help " <nl> + % 1 = string_literal objc_selector " help " <nl> + % 2 = function_ref @ helper : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . RawPointer ) - > Builtin . Word <nl> + % 3 = apply % 2 ( % 0 , % 1 ) : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . RawPointer ) - > Builtin . Word <nl> + return % 3 : $ Builtin . Word <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ raw_idx_cse : <nl> + / / CHECK : integer_literal <nl> + / / CHECK - NEXT : index_raw_pointer <nl> + / / CHECK - NEXT : pointer_to_address <nl> + / / CHECK - NEXT : load <nl> + / / CHECK - NEXT : load <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' raw_idx_cse ' <nl> + sil [ ossa ] @ raw_idx_cse : $ @ convention ( thin ) ( Builtin . RawPointer ) - > ( ) { <nl> + bb0 ( % 0 : $ Builtin . RawPointer ) : <nl> + % X = function_ref @ helper2 : $ @ convention ( thin ) ( UInt8 , UInt8 ) - > Builtin . Word <nl> + % 1 = integer_literal $ Builtin . Word , 5 <nl> + % 2 = index_raw_pointer % 0 : $ Builtin . RawPointer , % 1 : $ Builtin . Word <nl> + % 3 = index_raw_pointer % 0 : $ Builtin . RawPointer , % 1 : $ Builtin . Word <nl> + % 4 = pointer_to_address % 2 : $ Builtin . RawPointer to [ strict ] $ * UInt8 <nl> + % 5 = pointer_to_address % 3 : $ Builtin . RawPointer to [ strict ] $ * UInt8 <nl> + % 6 = load [ trivial ] % 4 : $ * UInt8 <nl> + % 7 = load [ trivial ] % 5 : $ * UInt8 <nl> + % 8 = apply % X ( % 6 , % 7 ) : $ @ convention ( thin ) ( UInt8 , UInt8 ) - > Builtin . Word <nl> + % Y = tuple ( ) <nl> + return % Y : $ ( ) <nl> + } <nl> + <nl> + enum FakeOptional { <nl> + case none <nl> + case some ( Builtin . Int32 ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ enum_cse : $ @ convention ( thin ) ( ) - > ( ) { <nl> + / / CHECK : bb0 <nl> + / / CHECK - NEXT : function_ref <nl> + / / CHECK - NEXT : [ [ FUNC : % [ 0 - 9 ] + ] ] = function_ref @ unknown_fake_optional_user : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + / / CHECK - NEXT : [ [ NONE : % [ 0 - 9 ] + ] ] = enum $ FakeOptional , # FakeOptional . none ! enumelt <nl> + / / CHECK - NEXT : apply [ [ FUNC ] ] ( [ [ NONE ] ] ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + / / CHECK - NEXT : apply [ [ FUNC ] ] ( [ [ NONE ] ] ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + / / CHECK - NEXT : [ [ INTEGER : % [ 0 - 9 ] + ] ] = integer_literal $ Builtin . Int32 , 0 <nl> + / / CHECK - NEXT : [ [ SOME : % [ 0 - 9 ] + ] ] = enum $ FakeOptional , # FakeOptional . some ! enumelt , [ [ INTEGER ] ] : $ Builtin . Int32 <nl> + / / CHECK - NEXT : apply [ [ FUNC ] ] ( [ [ SOME ] ] ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + / / CHECK - NEXT : apply [ [ FUNC ] ] ( [ [ SOME ] ] ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + / / CHECK - NEXT : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' enum_cse ' <nl> + sil [ ossa ] @ unknown_fake_optional_user : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + sil [ ossa ] @ enum_cse : $ @ convention ( thin ) ( ) - > ( ) { <nl> + bb0 : <nl> + % 0 = function_ref @ unknown_fake_optional_user : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + % 1 = enum $ FakeOptional , # FakeOptional . none ! enumelt <nl> + % 2 = enum $ FakeOptional , # FakeOptional . none ! enumelt <nl> + apply % 0 ( % 1 ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + apply % 0 ( % 2 ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + % 3 = integer_literal $ Builtin . Int32 , 0 <nl> + % 4 = enum $ FakeOptional , # FakeOptional . some ! enumelt , % 3 : $ Builtin . Int32 <nl> + % 5 = enum $ FakeOptional , # FakeOptional . some ! enumelt , % 3 : $ Builtin . Int32 <nl> + apply % 0 ( % 4 ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + apply % 0 ( % 5 ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + % 6 = tuple ( ) <nl> + return % 6 : $ ( ) <nl> + } <nl> + <nl> + sil [ ossa ] @ int32_user : $ @ convention ( thin ) ( Builtin . Int32 ) - > ( ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ unchecked_enum_data_cse : $ @ convention ( thin ) ( FakeOptional ) - > ( ) { <nl> + / / CHECK : bb0 ( [ [ INPUT_ENUM : % [ 0 - 9 ] + ] ] : $ FakeOptional ) : <nl> + / / CHECK - NEXT : function_ref <nl> + / / CHECK - NEXT : [ [ FUNC : % [ 0 - 9 ] + ] ] = function_ref @ int32_user : $ @ convention ( thin ) ( Builtin . Int32 ) - > ( ) <nl> + / / CHECK - NEXT : [ [ INT : % [ 0 - 9 ] + ] ] = unchecked_enum_data [ [ INPUT_ENUM ] ] : $ FakeOptional , # FakeOptional . some ! enumelt <nl> + / / CHECK - NEXT : apply [ [ FUNC ] ] ( [ [ INT ] ] ) : $ @ convention ( thin ) ( Builtin . Int32 ) - > ( ) <nl> + / / CHECK - NEXT : apply [ [ FUNC ] ] ( [ [ INT ] ] ) : $ @ convention ( thin ) ( Builtin . Int32 ) - > ( ) <nl> + / / CHECK - NEXT : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' unchecked_enum_data_cse ' <nl> + sil [ ossa ] @ unchecked_enum_data_cse : $ @ convention ( thin ) ( FakeOptional ) - > ( ) { <nl> + bb0 ( % 0 : $ FakeOptional ) : <nl> + % 1 = function_ref @ int32_user : $ @ convention ( thin ) ( Builtin . Int32 ) - > ( ) <nl> + % 2 = unchecked_enum_data % 0 : $ FakeOptional , # FakeOptional . some ! enumelt <nl> + % 3 = unchecked_enum_data % 0 : $ FakeOptional , # FakeOptional . some ! enumelt <nl> + apply % 1 ( % 2 ) : $ @ convention ( thin ) ( Builtin . Int32 ) - > ( ) <nl> + apply % 1 ( % 3 ) : $ @ convention ( thin ) ( Builtin . Int32 ) - > ( ) <nl> + % 6 = tuple ( ) <nl> + return % 6 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ test2cse : <nl> + / / CHECK : ref_to_raw_pointer <nl> + / / CHECK - NOT : ref_to_raw_pointer <nl> + / / CHECK : function_ref <nl> + / / CHECK : apply <nl> + / / CHECK - LABEL : } / / end sil function ' test2cse ' <nl> + sil [ ossa ] @ test2cse : $ @ convention ( thin ) ( @ owned C ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ C ) : <nl> + % 1 = ref_to_raw_pointer % 0 : $ C to $ Builtin . RawPointer <nl> + % 2 = ref_to_raw_pointer % 0 : $ C to $ Builtin . RawPointer <nl> + % 4 = function_ref @ helper : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . RawPointer ) - > Builtin . Word <nl> + % 5 = apply % 4 ( % 1 , % 2 ) : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . RawPointer ) - > Builtin . Word <nl> + destroy_value % 0 : $ C <nl> + % 6 = tuple ( ) <nl> + return % 6 : $ ( ) <nl> + } <nl> + <nl> + sil [ ossa ] @ helperCD : $ @ convention ( thin ) ( @ owned C , @ owned C ) - > Builtin . Word <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_index_addr_inst : <nl> + / / CHECK : bb0 ( <nl> + / / CHECK - NEXT : index_addr <nl> + / / CHECK - NEXT : address_to_pointer <nl> + / / CHECK - NEXT : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' cse_index_addr_inst ' <nl> + sil [ ossa ] @ cse_index_addr_inst : $ @ convention ( thin ) ( @ in D , Builtin . Word ) - > ( Builtin . RawPointer , Builtin . RawPointer ) { <nl> + bb0 ( % 0 : $ * D , % 1 : $ Builtin . Word ) : <nl> + % 2 = index_addr % 0 : $ * D , % 1 : $ Builtin . Word <nl> + % 3 = index_addr % 0 : $ * D , % 1 : $ Builtin . Word <nl> + % 4 = address_to_pointer % 2 : $ * D to $ Builtin . RawPointer <nl> + % 5 = address_to_pointer % 3 : $ * D to $ Builtin . RawPointer <nl> + % 6 = tuple ( % 4 : $ Builtin . RawPointer , % 5 : $ Builtin . RawPointer ) <nl> + return % 6 : $ ( Builtin . RawPointer , Builtin . RawPointer ) <nl> + } <nl> + <nl> + <nl> + sil [ ossa ] [ readnone ] @ readnonefun : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > Builtin . Int64 <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_readnone : <nl> + / / CHECK : bb0 <nl> + / / CHECK : function_ref @ readnonefun <nl> + / / CHECK : apply <nl> + / / CHECK - NOT : function_ref @ readnonefun <nl> + / / CHECK - NOT : apply <nl> + / / CHECK - LABEL : } / / end sil function ' cse_readnone ' <nl> + sil [ ossa ] @ cse_readnone : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > Builtin . Int64 { <nl> + bb0 ( % 0 : $ * Builtin . Int8 ) : <nl> + % 1 = function_ref @ readnonefun : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > Builtin . Int64 <nl> + % 3 = apply % 1 ( % 0 ) : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > Builtin . Int64 <nl> + % 2 = function_ref @ readnonefun : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > Builtin . Int64 <nl> + % 4 = apply % 2 ( % 0 ) : $ @ convention ( thin ) ( @ inout Builtin . Int8 ) - > Builtin . Int64 <nl> + return % 4 : $ Builtin . Int64 <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_raw_pointer_to_ref : <nl> + / / CHECK : raw_pointer_to_ref <nl> + / / CHECK - NOT : raw_pointer_to_ref <nl> + / / CHECK : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' cse_raw_pointer_to_ref ' <nl> + sil [ ossa ] @ cse_raw_pointer_to_ref : $ @ convention ( thin ) ( Builtin . RawPointer ) - > ( C , C ) { <nl> + bb0 ( % 0 : $ Builtin . RawPointer ) : <nl> + % 1 = raw_pointer_to_ref % 0 : $ Builtin . RawPointer to $ C <nl> + % 2 = raw_pointer_to_ref % 0 : $ Builtin . RawPointer to $ C <nl> + % 6 = tuple ( % 1 : $ C , % 2 : $ C ) <nl> + return % 6 : $ ( C , C ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_unchecked_addr_cast : <nl> + / / CHECK : unchecked_addr_cast <nl> + / / CHECK - NOT : unchecked_addr_cast <nl> + / / CHECK : struct_element_addr <nl> + / / CHECK : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' cse_unchecked_addr_cast ' <nl> + sil [ ossa ] @ cse_unchecked_addr_cast : $ @ convention ( thin ) ( ) - > ( Builtin . RawPointer , Builtin . RawPointer ) { <nl> + bb0 : <nl> + % 1 = alloc_stack $ OpaquePointer <nl> + % 2 = unchecked_addr_cast % 1 : $ * OpaquePointer to $ * UnsafeMutablePointer < AnyObject > <nl> + % 3 = unchecked_addr_cast % 1 : $ * OpaquePointer to $ * UnsafeMutablePointer < AnyObject > <nl> + % 4 = struct_element_addr % 2 : $ * UnsafeMutablePointer < AnyObject > , # UnsafeMutablePointer . _rawValue <nl> + % 5 = load [ trivial ] % 4 : $ * Builtin . RawPointer <nl> + % 6 = struct_element_addr % 3 : $ * UnsafeMutablePointer < AnyObject > , # UnsafeMutablePointer . _rawValue <nl> + % 7 = load [ trivial ] % 6 : $ * Builtin . RawPointer <nl> + % 8 = tuple ( % 5 : $ Builtin . RawPointer , % 7 : $ Builtin . RawPointer ) <nl> + dealloc_stack % 1 : $ * OpaquePointer <nl> + return % 8 : $ ( Builtin . RawPointer , Builtin . RawPointer ) <nl> + } <nl> + <nl> + enum Enum1 { <nl> + case Case1 <nl> + case Case2 <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_select_enum : <nl> + / / CHECK : select_enum <nl> + / / CHECK - NOT : select_enum <nl> + / / CHECK : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' cse_select_enum ' <nl> + sil [ ossa ] @ cse_select_enum : $ @ convention ( thin ) ( @ guaranteed Enum1 ) - > ( Builtin . Int1 , Builtin . Int1 ) { <nl> + bb0 ( % 0 : $ Enum1 ) : <nl> + % t = integer_literal $ Builtin . Int1 , 1 <nl> + % f = integer_literal $ Builtin . Int1 , 0 <nl> + % 1 = select_enum % 0 : $ Enum1 , case # Enum1 . Case1 ! enumelt : % t , case # Enum1 . Case2 ! enumelt : % f : $ Builtin . Int1 <nl> + % 2 = select_enum % 0 : $ Enum1 , case # Enum1 . Case1 ! enumelt : % t , case # Enum1 . Case2 ! enumelt : % f : $ Builtin . Int1 <nl> + % 3 = tuple ( % 1 : $ Builtin . Int1 , % 2 : $ Builtin . Int1 ) <nl> + return % 3 : $ ( Builtin . Int1 , Builtin . Int1 ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_bridge_object_to_word : <nl> + / / CHECK : [ [ REF : % [ 0 - 9 ] + ] ] = bridge_object_to_word <nl> + / / CHECK - NOT : bridge_object_to_word <nl> + / / CHECK : tuple ( [ [ REF ] ] : $ Builtin . Word , [ [ REF ] ] : $ Builtin . Word ) <nl> + / / CHECK - LABEL : } / / end sil function ' cse_bridge_object_to_word ' <nl> + sil [ ossa ] @ cse_bridge_object_to_word : $ @ convention ( thin ) ( @ owned Builtin . BridgeObject ) - > ( Builtin . Word , Builtin . Word ) { <nl> + bb0 ( % 0 : @ owned $ Builtin . BridgeObject ) : <nl> + % 1 = bridge_object_to_word % 0 : $ Builtin . BridgeObject to $ Builtin . Word <nl> + % 2 = bridge_object_to_word % 0 : $ Builtin . BridgeObject to $ Builtin . Word <nl> + % 3 = tuple ( % 1 : $ Builtin . Word , % 2 : $ Builtin . Word ) <nl> + destroy_value % 0 : $ Builtin . BridgeObject <nl> + return % 3 : $ ( Builtin . Word , Builtin . Word ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_thin_function_to_pointer : <nl> + / / CHECK : [ [ REF : % [ 0 - 9 ] + ] ] = thin_function_to_pointer <nl> + / / CHECK - NOT : thin_function_to_pointer <nl> + / / CHECK : tuple ( [ [ REF ] ] : $ Builtin . RawPointer , [ [ REF ] ] : $ Builtin . RawPointer ) <nl> + / / CHECK - LABEL : } / / end sil function ' cse_thin_function_to_pointer ' <nl> + sil [ ossa ] @ cse_thin_function_to_pointer : $ @ convention ( thin ) ( @ convention ( thin ) ( ) - > ( ) ) - > ( Builtin . RawPointer , Builtin . RawPointer ) { <nl> + bb0 ( % 0 : $ @ convention ( thin ) ( ) - > ( ) ) : <nl> + % 1 = thin_function_to_pointer % 0 : $ @ convention ( thin ) ( ) - > ( ) to $ Builtin . RawPointer <nl> + % 2 = thin_function_to_pointer % 0 : $ @ convention ( thin ) ( ) - > ( ) to $ Builtin . RawPointer <nl> + % 3 = tuple ( % 1 : $ Builtin . RawPointer , % 2 : $ Builtin . RawPointer ) <nl> + return % 3 : $ ( Builtin . RawPointer , Builtin . RawPointer ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_pointer_to_thin_function : <nl> + / / CHECK : [ [ REF : % [ 0 - 9 ] + ] ] = pointer_to_thin_function <nl> + / / CHECK - NOT : pointer_to_thin_function <nl> + / / CHECK : tuple ( [ [ REF ] ] : $ @ convention ( thin ) ( ) - > ( ) , [ [ REF ] ] : $ @ convention ( thin ) ( ) - > ( ) ) <nl> + / / CHECK - LABEL : } / / end sil function ' cse_pointer_to_thin_function ' <nl> + sil [ ossa ] @ cse_pointer_to_thin_function : $ @ convention ( thin ) ( Builtin . RawPointer ) - > ( @ convention ( thin ) ( ) - > ( ) , @ convention ( thin ) ( ) - > ( ) ) { <nl> + bb0 ( % 0 : $ Builtin . RawPointer ) : <nl> + % 1 = pointer_to_thin_function % 0 : $ Builtin . RawPointer to $ @ convention ( thin ) ( ) - > ( ) <nl> + % 2 = pointer_to_thin_function % 0 : $ Builtin . RawPointer to $ @ convention ( thin ) ( ) - > ( ) <nl> + % 3 = tuple ( % 1 : $ @ convention ( thin ) ( ) - > ( ) , % 2 : $ @ convention ( thin ) ( ) - > ( ) ) <nl> + return % 3 : $ ( @ convention ( thin ) ( ) - > ( ) , @ convention ( thin ) ( ) - > ( ) ) <nl> + } <nl> + <nl> + sil [ ossa ] [ _semantics " array . get_count " ] @ getCount : $ @ convention ( method ) ( @ guaranteed Array < Int > ) - > Int <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ dont_cse_get_count_on_low_level_sil : <nl> + / / CHECK : [ [ R1 : % [ 0 - 9 ] + ] ] = apply <nl> + / / CHECK : [ [ R2 : % [ 0 - 9 ] + ] ] = apply <nl> + / / CHECK : tuple ( [ [ R1 ] ] : $ Int , [ [ R2 ] ] : $ Int ) <nl> + / / CHECK - LABEL : } / / end sil function ' dont_cse_get_count_on_low_level_sil ' <nl> + sil [ ossa ] @ dont_cse_get_count_on_low_level_sil : $ @ convention ( thin ) ( @ guaranteed Array < Int > ) - > ( Int , Int ) { <nl> + bb0 ( % 0 : @ guaranteed $ Array < Int > ) : <nl> + % f1 = function_ref @ getCount : $ @ convention ( method ) ( @ guaranteed Array < Int > ) - > Int <nl> + % c1 = apply % f1 ( % 0 ) : $ @ convention ( method ) ( @ guaranteed Array < Int > ) - > Int <nl> + % c2 = apply % f1 ( % 0 ) : $ @ convention ( method ) ( @ guaranteed Array < Int > ) - > Int <nl> + % r1 = tuple ( % c1 : $ Int , % c2 : $ Int ) <nl> + return % r1 : $ ( Int , Int ) <nl> + } <nl> + <nl> + <nl> + sil [ ossa ] @ _TFC4main4Ping4pingfS0_FT_S0_ : $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + sil [ ossa ] @ _TFC4main4PingD : $ @ convention ( method ) ( @ owned Ping ) - > ( ) <nl> + sil [ ossa ] @ _TFC4main4PingcfMS0_FT_S0_ : $ @ convention ( method ) ( @ owned Ping ) - > @ owned Ping <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ _TF4main4ringFCS_4PingT_ : <nl> + / / CHECK : bb0 ( % 0 : @ owned $ Ping ) : <nl> + / / CHECK - NEXT : class_method <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - LABEL : } / / end sil function ' _TF4main4ringFCS_4PingT_ ' <nl> + sil [ ossa ] @ _TF4main4ringFCS_4PingT_ : $ @ convention ( thin ) ( @ owned Ping ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ Ping ) : <nl> + % 1 = class_method % 0 : $ Ping , # Ping . ping : ( Ping ) - > ( ) - > Ping , $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 2 = class_method % 0 : $ Ping , # Ping . ping : ( Ping ) - > ( ) - > Ping , $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 3 = class_method % 0 : $ Ping , # Ping . ping : ( Ping ) - > ( ) - > Ping , $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 4 = class_method % 0 : $ Ping , # Ping . ping : ( Ping ) - > ( ) - > Ping , $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 5 = class_method % 0 : $ Ping , # Ping . ping : ( Ping ) - > ( ) - > Ping , $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 6 = apply % 1 ( % 0 ) : $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 7 = apply % 2 ( % 0 ) : $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 8 = apply % 3 ( % 0 ) : $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 9 = apply % 4 ( % 0 ) : $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + destroy_value % 6 : $ Ping <nl> + destroy_value % 7 : $ Ping <nl> + destroy_value % 8 : $ Ping <nl> + destroy_value % 9 : $ Ping <nl> + destroy_value % 0 : $ Ping <nl> + % 10 = tuple ( ) <nl> + return % 10 : $ ( ) <nl> + } <nl> + <nl> + sil_vtable Ping { <nl> + # Ping . ping : @ _TFC4main4Ping4pingfS0_FT_S0_ / / main . Ping . ping ( main . Ping ) ( ) - > main . Ping <nl> + # Ping . deinit ! deallocator : @ _TFC4main4PingD / / main . Ping . __deallocating_deinit <nl> + # Ping . init ! initializer : @ _TFC4main4PingcfMS0_FT_S0_ / / main . Ping . init ( main . Ping . Type ) ( ) - > main . Ping <nl> + } <nl> + <nl> + protocol Reachable { <nl> + func reach ( ) <nl> + } <nl> + <nl> + class T : Reachable { <nl> + func reach ( ) <nl> + deinit <nl> + init ( ) <nl> + } <nl> + <nl> + func foo < T : Reachable > ( x : T , a : Int ) <nl> + <nl> + / / p . T . reach ( p . T ) ( ) - > ( ) <nl> + sil hidden [ ossa ] @ _TFC1p1T5reachfS0_FT_T_ : $ @ convention ( method ) ( @ guaranteed T ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ T ) : <nl> + debug_value % 0 : $ T , let , name " self " <nl> + % 2 = tuple ( ) <nl> + return % 2 : $ ( ) <nl> + } <nl> + <nl> + / / p . T . __deallocating_deinit <nl> + sil hidden [ ossa ] @ _TFC1p1TD : $ @ convention ( method ) ( @ owned T ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ T ) : <nl> + debug_value % 0 : $ T , let , name " self " <nl> + destroy_value % 0 : $ T <nl> + % 6 = tuple ( ) <nl> + return % 6 : $ ( ) <nl> + } <nl> + <nl> + / / p . T . deinit <nl> + sil hidden [ ossa ] @ _TFC1p1Td : $ @ convention ( method ) ( @ guaranteed T ) - > @ owned Builtin . NativeObject { <nl> + bb0 ( % 0 : @ guaranteed $ T ) : <nl> + debug_value % 0 : $ T , let , name " self " <nl> + % copy = copy_value % 0 : $ T <nl> + % 2 = unchecked_ref_cast % copy : $ T to $ Builtin . NativeObject <nl> + return % 2 : $ Builtin . NativeObject <nl> + } <nl> + <nl> + / / p . T . init ( p . T . Type ) ( ) - > p . T <nl> + sil hidden [ ossa ] @ _TFC1p1TcfMS0_FT_S0_ : $ @ convention ( method ) ( @ owned T ) - > @ owned T { <nl> + bb0 ( % 0 : @ owned $ T ) : <nl> + debug_value % 0 : $ T , let , name " self " <nl> + return % 0 : $ T <nl> + } <nl> + <nl> + / / protocol witness for p . Reachable . reach < A where A : p . Reachable > ( A ) ( ) - > ( ) in conformance p . T : p . Reachable in p <nl> + sil hidden [ ossa ] [ transparent ] [ thunk ] @ _TTWC1p1TS_9ReachableS_FS1_5reachuRq_S1__fq_FT_T_ : $ @ convention ( witness_method : Reachable ) ( @ in_guaranteed T ) - > ( ) { <nl> + bb0 ( % 0 : $ * T ) : <nl> + % 1 = load [ copy ] % 0 : $ * T <nl> + % 3 = class_method % 1 : $ T , # T . reach : ( T ) - > ( ) - > ( ) , $ @ convention ( method ) ( @ guaranteed T ) - > ( ) <nl> + % 4 = apply % 3 ( % 1 ) : $ @ convention ( method ) ( @ guaranteed T ) - > ( ) <nl> + destroy_value % 1 : $ T <nl> + return % 4 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil hidden [ ossa ] @ _TF1p3foouRq_S_9Reachable_FTq_1aSi_T_ : <nl> + / / CHECK : bb0 ( % 0 : $ * T , % 1 : $ Int ) : <nl> + / / CHECK - NEXT : witness_method <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : destroy_addr <nl> + / / CHECK - NEXT : tuple <nl> + / / p . foo < A where A : p . Reachable > ( A , a : Swift . Int ) - > ( ) <nl> + / / CHECK - LABEL : } / / end sil function ' _TF1p3foouRq_S_9Reachable_FTq_1aSi_T_ ' <nl> + sil hidden [ ossa ] @ _TF1p3foouRq_S_9Reachable_FTq_1aSi_T_ : $ @ convention ( thin ) < T where T : Reachable > ( @ in T , Int ) - > ( ) { <nl> + bb0 ( % 0 : $ * T , % 1 : $ Int ) : <nl> + % 4 = witness_method $ T , # Reachable . reach : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 5 = apply % 4 < T > ( % 0 ) : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 6 = witness_method $ T , # Reachable . reach : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 7 = apply % 6 < T > ( % 0 ) : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 8 = witness_method $ T , # Reachable . reach : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 9 = apply % 8 < T > ( % 0 ) : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 10 = witness_method $ T , # Reachable . reach : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 11 = apply % 10 < T > ( % 0 ) : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 12 = witness_method $ T , # Reachable . reach : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 13 = apply % 12 < T > ( % 0 ) : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 14 = witness_method $ T , # Reachable . reach : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 15 = apply % 14 < T > ( % 0 ) : $ @ convention ( witness_method : Reachable ) < τ_0_0 where τ_0_0 : Reachable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + destroy_addr % 0 : $ * T <nl> + % 17 = tuple ( ) <nl> + return % 17 : $ ( ) <nl> + } <nl> + <nl> + sil_vtable T { <nl> + # T . reach : @ _TFC1p1T5reachfS0_FT_T_ / / p . T . reach ( p . T ) ( ) - > ( ) <nl> + # T . deinit ! deallocator : @ _TFC1p1TD / / p . T . __deallocating_deinit <nl> + # T . init ! initializer : @ _TFC1p1TcfMS0_FT_S0_ / / p . T . init ( p . T . Type ) ( ) - > p . T <nl> + } <nl> + <nl> + sil_witness_table hidden T : Reachable module p { <nl> + method # Reachable . reach : @ _TTWC1p1TS_9ReachableS_FS1_5reachuRq_S1__fq_FT_T_ / / protocol witness for p . Reachable . reach < A where A : p . Reachable > ( A ) ( ) - > ( ) in conformance p . T : p . Reachable in p <nl> + } <nl> + <nl> + protocol Flyable { <nl> + func fly ( ) <nl> + } <nl> + <nl> + struct Airplane : Flyable { <nl> + func fly ( ) <nl> + init ( ) <nl> + } <nl> + <nl> + func trytofly ( a : Flyable ) <nl> + <nl> + / / p2 . Airplane . fly ( p2 . Airplane ) ( ) - > ( ) <nl> + sil hidden [ ossa ] @ _TFV2p28Airplane3flyfS0_FT_T_ : $ @ convention ( method ) ( Airplane ) - > ( ) { <nl> + bb0 ( % 0 : $ Airplane ) : <nl> + debug_value % 0 : $ Airplane , let , name " self " <nl> + % 2 = tuple ( ) <nl> + return % 2 : $ ( ) <nl> + } <nl> + <nl> + / / protocol witness for p2 . Flyable . fly < A where A : p2 . Flyable > ( A ) ( ) - > ( ) in conformance p2 . Airplane : p2 . Flyable in p2 <nl> + sil hidden [ ossa ] [ transparent ] [ thunk ] @ _TTWV2p28AirplaneS_7FlyableS_FS1_3flyuRq_S1__fq_FT_T_ : $ @ convention ( witness_method : Flyable ) ( @ in_guaranteed Airplane ) - > ( ) { <nl> + bb0 ( % 0 : $ * Airplane ) : <nl> + % 1 = alloc_stack $ Airplane <nl> + copy_addr % 0 to [ initialization ] % 1 : $ * Airplane <nl> + % 3 = struct $ Airplane ( ) <nl> + / / function_ref p2 . Airplane . fly ( p2 . Airplane ) ( ) - > ( ) <nl> + % 4 = function_ref @ _TFV2p28Airplane3flyfS0_FT_T_ : $ @ convention ( method ) ( Airplane ) - > ( ) <nl> + % 5 = apply % 4 ( % 3 ) : $ @ convention ( method ) ( Airplane ) - > ( ) <nl> + dealloc_stack % 1 : $ * Airplane <nl> + return % 5 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil hidden [ ossa ] @ _TF2p28trytoflyFPS_7Flyable_T_ : <nl> + / / CHECK : bb0 ( % 0 : $ * Flyable ) : <nl> + / / CHECK - NEXT : open_existential_addr <nl> + / / CHECK - NEXT : witness_method <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : open_existential_addr <nl> + / / CHECK - NEXT : witness_method <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : open_existential_addr <nl> + / / CHECK - NEXT : witness_method <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : apply <nl> + / / CHECK - NEXT : destroy_addr <nl> + / / CHECK - NEXT : tuple <nl> + / / p2 . trytofly ( p2 . Flyable ) - > ( ) <nl> + / / CHECK - LABEL : } / / end sil function ' _TF2p28trytoflyFPS_7Flyable_T_ ' <nl> + sil hidden [ ossa ] @ _TF2p28trytoflyFPS_7Flyable_T_ : $ @ convention ( thin ) ( @ in Flyable ) - > ( ) { <nl> + bb0 ( % 0 : $ * Flyable ) : <nl> + % 2 = open_existential_addr immutable_access % 0 : $ * Flyable to $ * @ opened ( " D8A4A5D8 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable <nl> + % 3 = witness_method $ @ opened ( " D8A4A5D8 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable , # Flyable . fly , % 2 : $ * @ opened ( " D8A4A5D8 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable : $ @ convention ( witness_method : Flyable ) < τ_0_0 where τ_0_0 : Flyable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 4 = apply % 3 < @ opened ( " D8A4A5D8 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable > ( % 2 ) : $ @ convention ( witness_method : Flyable ) < τ_0_0 where τ_0_0 : Flyable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 5 = open_existential_addr immutable_access % 0 : $ * Flyable to $ * @ opened ( " D8A4B49C - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable <nl> + % 6 = witness_method $ @ opened ( " D8A4B49C - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable , # Flyable . fly , % 5 : $ * @ opened ( " D8A4B49C - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable : $ @ convention ( witness_method : Flyable ) < τ_0_0 where τ_0_0 : Flyable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 7 = apply % 6 < @ opened ( " D8A4B49C - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable > ( % 5 ) : $ @ convention ( witness_method : Flyable ) < τ_0_0 where τ_0_0 : Flyable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 8 = open_existential_addr immutable_access % 0 : $ * Flyable to $ * @ opened ( " D8A4BCB2 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable <nl> + % 9 = witness_method $ @ opened ( " D8A4BCB2 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable , # Flyable . fly , % 8 : $ * @ opened ( " D8A4BCB2 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable : $ @ convention ( witness_method : Flyable ) < τ_0_0 where τ_0_0 : Flyable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 10 = apply % 9 < @ opened ( " D8A4BCB2 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable > ( % 8 ) : $ @ convention ( witness_method : Flyable ) < τ_0_0 where τ_0_0 : Flyable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 11 = witness_method $ @ opened ( " D8A4BCB2 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable , # Flyable . fly , % 8 : $ * @ opened ( " D8A4BCB2 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable : $ @ convention ( witness_method : Flyable ) < τ_0_0 where τ_0_0 : Flyable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 12 = apply % 9 < @ opened ( " D8A4BCB2 - 4C44 - 11E5 - BA43 - AC87A3294C0A " ) Flyable > ( % 8 ) : $ @ convention ( witness_method : Flyable ) < τ_0_0 where τ_0_0 : Flyable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + destroy_addr % 0 : $ * Flyable <nl> + % 13 = tuple ( ) <nl> + return % 13 : $ ( ) <nl> + } <nl> + <nl> + sil_witness_table hidden Airplane : Flyable module p2 { <nl> + method # Flyable . fly : @ _TTWV2p28AirplaneS_7FlyableS_FS1_3flyuRq_S1__fq_FT_T_ / / protocol witness for p2 . Flyable . fly < A where A : p2 . Flyable > ( A ) ( ) - > ( ) in conformance p2 . Airplane : p2 . Flyable in p2 <nl> + } <nl> + <nl> + <nl> + protocol Pingable { func ping ( ) } <nl> + <nl> + / / CHECK - LABEL : sil hidden [ ossa ] @ CSE_Existential_Simple : <nl> + / / CHECK : open_existential_addr immutable_access % 0 : $ * Pingable to $ * @ opened ( " 1E467EB8 - D5C5 - 11E5 - 8C0E - A82066121073 " ) <nl> + / / CHECK : witness_method $ @ opened ( " 1E467EB8 - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable , # Pingable . ping : { { . * } } , % 2 <nl> + / / CHECK : apply % 3 < @ opened ( " 1E467EB8 - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable > ( % 2 ) <nl> + / / CHECK : open_existential_addr immutable_access <nl> + / / CHECK : witness_method <nl> + / / CHECK : apply % 3 < @ opened ( " 1E467EB8 - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable > ( % 2 ) <nl> + / / CHECK - LABEL : } / / end sil function ' CSE_Existential_Simple ' <nl> + sil hidden [ ossa ] @ CSE_Existential_Simple : $ @ convention ( thin ) ( @ in Pingable ) - > ( ) { <nl> + bb0 ( % 0 : $ * Pingable ) : <nl> + debug_value_addr % 0 : $ * Pingable / / let x <nl> + % 2 = open_existential_addr immutable_access % 0 : $ * Pingable to $ * @ opened ( " 1E467EB8 - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable <nl> + % 3 = witness_method $ @ opened ( " 1E467EB8 - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable , # Pingable . ping , % 2 : $ * @ opened ( " 1E467EB8 - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable : $ @ convention ( witness_method : Pingable ) < τ_0_0 where τ_0_0 : Pingable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 4 = apply % 3 < @ opened ( " 1E467EB8 - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable > ( % 2 ) : $ @ convention ( witness_method : Pingable ) < τ_0_0 where τ_0_0 : Pingable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 5 = open_existential_addr immutable_access % 0 : $ * Pingable to $ * @ opened ( " 1E4687DC - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable <nl> + % 6 = witness_method $ @ opened ( " 1E4687DC - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable , # Pingable . ping , % 5 : $ * @ opened ( " 1E4687DC - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable : $ @ convention ( witness_method : Pingable ) < τ_0_0 where τ_0_0 : Pingable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 7 = apply % 6 < @ opened ( " 1E4687DC - D5C5 - 11E5 - 8C0E - A82066121073 " ) Pingable > ( % 5 ) : $ @ convention ( witness_method : Pingable ) < τ_0_0 where τ_0_0 : Pingable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + destroy_addr % 0 : $ * Pingable <nl> + % 9 = tuple ( ) <nl> + return % 9 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil hidden [ ossa ] @ CSE_Existential_Calls_With_Control_Flow : <nl> + sil hidden [ ossa ] @ CSE_Existential_Calls_With_Control_Flow : $ @ convention ( thin ) ( @ in Pingable , Int ) - > ( ) { <nl> + bb0 ( % 0 : $ * Pingable , % 1 : $ Int ) : <nl> + debug_value_addr % 0 : $ * Pingable / / let x <nl> + debug_value % 1 : $ Int / / let y <nl> + % 4 = open_existential_addr immutable_access % 0 : $ * Pingable to $ * @ opened ( " 75F1B81A - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable <nl> + % 5 = witness_method $ @ opened ( " 75F1B81A - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable , # Pingable . ping , % 4 : $ * @ opened ( " 75F1B81A - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable : $ @ convention ( witness_method : Pingable ) < τ_0_0 where τ_0_0 : Pingable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + <nl> + / / CHECK : apply % 5 < @ opened ( " 75F1B81A - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable > ( % 4 ) <nl> + % 6 = apply % 5 < @ opened ( " 75F1B81A - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable > ( % 4 ) : $ @ convention ( witness_method : Pingable ) < τ_0_0 where τ_0_0 : Pingable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + % 7 = integer_literal $ Builtin . Int64 , 3 <nl> + % 8 = integer_literal $ Builtin . Int64 , 3 <nl> + % 9 = builtin " cmp_sgt_Int64 " ( % 8 : $ Builtin . Int64 , % 7 : $ Builtin . Int64 ) : $ Builtin . Int1 <nl> + cond_br % 9 , bb1 , bb2 <nl> + <nl> + bb1 : <nl> + % 11 = open_existential_addr immutable_access % 0 : $ * Pingable to $ * @ opened ( " 75F1F3AC - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable <nl> + % 12 = witness_method $ @ opened ( " 75F1F3AC - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable , # Pingable . ping , % 11 : $ * @ opened ( " 75F1F3AC - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable : $ @ convention ( witness_method : Pingable ) < τ_0_0 where τ_0_0 : Pingable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + <nl> + / / CHECK : apply % 5 < @ opened ( " 75F1B81A - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable > ( % 4 ) <nl> + % 13 = apply % 12 < @ opened ( " 75F1F3AC - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable > ( % 11 ) : $ @ convention ( witness_method : Pingable ) < τ_0_0 where τ_0_0 : Pingable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + br bb3 <nl> + <nl> + bb2 : <nl> + br bb3 <nl> + <nl> + bb3 : <nl> + % 15 = open_existential_addr immutable_access % 0 : $ * Pingable to $ * @ opened ( " 75F1F5C8 - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable <nl> + % 16 = witness_method $ @ opened ( " 75F1F5C8 - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable , # Pingable . ping , % 15 : $ * @ opened ( " 75F1F5C8 - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable : $ @ convention ( witness_method : Pingable ) < τ_0_0 where τ_0_0 : Pingable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + <nl> + / / CHECK : apply % 5 < @ opened ( " 75F1B81A - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable > ( % 4 ) <nl> + % 17 = apply % 16 < @ opened ( " 75F1F5C8 - D6CB - 11E5 - 9470 - A82066121073 " ) Pingable > ( % 15 ) : $ @ convention ( witness_method : Pingable ) < τ_0_0 where τ_0_0 : Pingable > ( @ in_guaranteed τ_0_0 ) - > ( ) <nl> + destroy_addr % 0 : $ * Pingable <nl> + % 19 = tuple ( ) <nl> + <nl> + return % 19 : $ ( ) <nl> + } <nl> + / / CHECK - LABEL : } / / end sil function ' CSE_Existential_Calls_With_Control_Flow ' <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_mark_dependence : <nl> + / / CHECK : mark_dependence <nl> + / / CHECK - NOT : mark_dependence <nl> + / / CHECK - LABEL : } / / end sil function ' cse_mark_dependence ' <nl> + sil [ ossa ] @ cse_mark_dependence : $ @ convention ( thin ) ( @ inout Builtin . Int64 , @ guaranteed Builtin . NativeObject ) - > ( Builtin . Int64 , Builtin . Int64 ) { <nl> + bb0 ( % 0 : $ * Builtin . Int64 , % 1 : @ guaranteed $ Builtin . NativeObject ) : <nl> + % 2 = mark_dependence % 0 : $ * Builtin . Int64 on % 1 : $ Builtin . NativeObject <nl> + % 3 = mark_dependence % 0 : $ * Builtin . Int64 on % 1 : $ Builtin . NativeObject <nl> + % 4 = load [ trivial ] % 2 : $ * Builtin . Int64 <nl> + % 5 = load [ trivial ] % 3 : $ * Builtin . Int64 <nl> + % 6 = tuple ( % 4 : $ Builtin . Int64 , % 5 : $ Builtin . Int64 ) <nl> + return % 6 : $ ( Builtin . Int64 , Builtin . Int64 ) <nl> + } <nl> + <nl> + protocol Proto : class { <nl> + func doThis ( ) <nl> + func doThat ( ) <nl> + } <nl> + <nl> + / / Check that we don ' t CSE open_existential_ref if they are not compeltely equal . <nl> + / / CHECK - LABEL : sil [ ossa ] @ dont_cse_open_existential_ref : <nl> + / / CHECK : open_existential_ref <nl> + / / CHECK : open_existential_ref <nl> + / / CHECK - LABEL : } / / end sil function ' dont_cse_open_existential_ref ' <nl> + sil [ ossa ] @ dont_cse_open_existential_ref : $ @ convention ( thin ) ( @ guaranteed Proto & Ping ) - > @ owned Ping { <nl> + bb0 ( % 0 : @ guaranteed $ Proto & Ping ) : <nl> + % 4 = open_existential_ref % 0 : $ Proto & Ping to $ @ opened ( " 1B68354A - 4796 - 11E6 - B7DF - B8E856428C60 " ) Proto <nl> + % 5 = witness_method $ @ opened ( " 1B68354A - 4796 - 11E6 - B7DF - B8E856428C60 " ) Proto , # Proto . doThis , % 4 : $ @ opened ( " 1B68354A - 4796 - 11E6 - B7DF - B8E856428C60 " ) Proto : $ @ convention ( witness_method : Proto ) < τ_0_0 where τ_0_0 : Proto > ( @ guaranteed τ_0_0 ) - > ( ) <nl> + % 6 = apply % 5 < @ opened ( " 1B68354A - 4796 - 11E6 - B7DF - B8E856428C60 " ) Proto > ( % 4 ) : $ @ convention ( witness_method : Proto ) < τ_0_0 where τ_0_0 : Proto > ( @ guaranteed τ_0_0 ) - > ( ) <nl> + % 9 = open_existential_ref % 0 : $ Proto & Ping to $ @ opened ( " 3C038746 - BE69 - 11E7 - A5C1 - 685B35C48C83 " ) Proto & Ping <nl> + % 10 = upcast % 9 : $ @ opened ( " 3C038746 - BE69 - 11E7 - A5C1 - 685B35C48C83 " ) Proto & Ping to $ Ping <nl> + % 11 = class_method % 10 : $ Ping , # Ping . ping : ( Ping ) - > ( ) - > Ping , $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 12 = apply % 11 ( % 10 ) : $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + return % 12 : $ Ping <nl> + } <nl> + <nl> + sil [ ossa ] [ global_init ] @ $ s4test10testGlobalSivau : $ @ convention ( thin ) ( ) - > Builtin . RawPointer <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_global_init : <nl> + / / CHECK : [ [ P : % [ 0 - 9 ] + ] ] = apply <nl> + / / CHECK : [ [ A : % [ 0 - 9 ] + ] ] = pointer_to_address [ [ P ] ] <nl> + / / CHECK : begin_access [ modify ] [ dynamic ] [ no_nested_conflict ] [ [ A ] ] <nl> + / / CHECK : begin_access [ read ] [ dynamic ] [ no_nested_conflict ] [ [ A ] ] <nl> + / / CHECK : / / end sil function ' cse_global_init ' <nl> + sil [ ossa ] @ cse_global_init : $ @ convention ( thin ) ( ) - > Int64 { <nl> + bb0 : <nl> + % 2 = function_ref @ $ s4test10testGlobalSivau : $ @ convention ( thin ) ( ) - > Builtin . RawPointer <nl> + % 3 = apply % 2 ( ) : $ @ convention ( thin ) ( ) - > Builtin . RawPointer <nl> + % 4 = pointer_to_address % 3 : $ Builtin . RawPointer to [ strict ] $ * Int64 <nl> + % 5 = integer_literal $ Builtin . Int64 , 42 <nl> + % 6 = struct $ Int64 ( % 5 : $ Builtin . Int64 ) <nl> + % 7 = begin_access [ modify ] [ dynamic ] [ no_nested_conflict ] % 4 : $ * Int64 <nl> + store % 6 to [ trivial ] % 7 : $ * Int64 <nl> + end_access % 7 : $ * Int64 <nl> + % 10 = function_ref @ $ s4test10testGlobalSivau : $ @ convention ( thin ) ( ) - > Builtin . RawPointer <nl> + % 11 = apply % 10 ( ) : $ @ convention ( thin ) ( ) - > Builtin . RawPointer <nl> + % 12 = pointer_to_address % 11 : $ Builtin . RawPointer to [ strict ] $ * Int64 <nl> + % 33 = begin_access [ read ] [ dynamic ] [ no_nested_conflict ] % 12 : $ * Int64 <nl> + % 35 = load [ trivial ] % 33 : $ * Int64 <nl> + end_access % 33 : $ * Int64 <nl> + return % 35 : $ Int64 <nl> + } <nl> + <nl> + / / Test init_existential_metatype combining . <nl> + protocol SomeP { } <nl> + <nl> + public enum SpecialEnum : SomeP { } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ testCSEInitExistentialMetatype : $ @ convention ( thin ) ( @ thick SpecialEnum . Type ) - > Bool { <nl> + / / CHECK : [ [ EMT : % . * ] ] = init_existential_metatype % 0 : $ @ thick SpecialEnum . Type , $ @ thick Any . Type <nl> + / / CHECK - NOT : init_existential_metatype <nl> + / / CHECK : builtin " is_same_metatype " ( [ [ EMT ] ] : $ @ thick Any . Type , [ [ EMT ] ] : $ @ thick Any . Type ) : $ Builtin . Int1 <nl> + / / CHECK - LABEL : } / / end sil function ' testCSEInitExistentialMetatype ' <nl> + sil [ ossa ] @ testCSEInitExistentialMetatype : $ @ convention ( thin ) ( @ thick SpecialEnum . Type ) - > Bool { <nl> + bb0 ( % 0 : $ @ thick SpecialEnum . Type ) : <nl> + % 1 = init_existential_metatype % 0 : $ @ thick SpecialEnum . Type , $ @ thick Any . Type <nl> + % 2 = init_existential_metatype % 0 : $ @ thick SpecialEnum . Type , $ @ thick Any . Type <nl> + % 3 = builtin " is_same_metatype " ( % 1 : $ @ thick Any . Type , % 2 : $ @ thick Any . Type ) : $ Builtin . Int1 <nl> + % 4 = struct $ Bool ( % 3 : $ Builtin . Int1 ) <nl> + return % 4 : $ Bool <nl> + } <nl> + <nl> + struct StructWithLazyProperty { <nl> + var lazyProperty : Int64 { mutating get set } <nl> + @ _hasStorage @ _hasInitialValue var lazyPropertyStorage : Int64 ? { get set } <nl> + } <nl> + <nl> + sil private [ ossa ] [ lazy_getter ] [ noinline ] @ lazy_getter : $ @ convention ( method ) ( @ inout StructWithLazyProperty ) - > Int64 { <nl> + bb0 ( % 0 : $ * StructWithLazyProperty ) : <nl> + % 2 = struct_element_addr % 0 : $ * StructWithLazyProperty , # StructWithLazyProperty . lazyPropertyStorage <nl> + % 3 = load [ trivial ] % 2 : $ * Optional < Int64 > <nl> + switch_enum % 3 : $ Optional < Int64 > , case # Optional . some ! enumelt : bb1 , case # Optional . none ! enumelt : bb2 <nl> + <nl> + bb1 ( % 5 : $ Int64 ) : <nl> + br bb3 ( % 5 : $ Int64 ) <nl> + <nl> + bb2 : <nl> + % 9 = integer_literal $ Builtin . Int64 , 27 <nl> + % 10 = struct $ Int64 ( % 9 : $ Builtin . Int64 ) <nl> + % 12 = enum $ Optional < Int64 > , # Optional . some ! enumelt , % 10 : $ Int64 <nl> + store % 12 to [ trivial ] % 2 : $ * Optional < Int64 > <nl> + br bb3 ( % 10 : $ Int64 ) <nl> + <nl> + bb3 ( % 15 : $ Int64 ) : <nl> + return % 15 : $ Int64 <nl> + } <nl> + <nl> + sil [ ossa ] @ take_int : $ @ convention ( thin ) ( Int64 ) - > ( ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ dont_cse_lazy_property_of_overwritten_struct : $ @ convention ( thin ) ( ) - > ( ) { <nl> + / / CHECK : [ [ GETTER : % [ 0 - 9 ] + ] ] = function_ref @ lazy_getter <nl> + / / CHECK : apply [ [ GETTER ] ] <nl> + / / CHECK : apply [ [ GETTER ] ] <nl> + / / CHECK : } / / end sil function ' dont_cse_lazy_property_of_overwritten_struct ' <nl> + sil [ ossa ] @ dont_cse_lazy_property_of_overwritten_struct : $ @ convention ( thin ) ( ) - > ( ) { <nl> + bb0 : <nl> + % 0 = alloc_stack $ StructWithLazyProperty <nl> + % 4 = enum $ Optional < Int64 > , # Optional . none ! enumelt <nl> + % 5 = struct $ StructWithLazyProperty ( % 4 : $ Optional < Int64 > ) <nl> + store % 5 to [ trivial ] % 0 : $ * StructWithLazyProperty <nl> + % 7 = function_ref @ lazy_getter : $ @ convention ( method ) ( @ inout StructWithLazyProperty ) - > Int64 <nl> + % 8 = apply % 7 ( % 0 ) : $ @ convention ( method ) ( @ inout StructWithLazyProperty ) - > Int64 <nl> + % 9 = function_ref @ take_int : $ @ convention ( thin ) ( Int64 ) - > ( ) <nl> + % 10 = apply % 9 ( % 8 ) : $ @ convention ( thin ) ( Int64 ) - > ( ) <nl> + store % 5 to [ trivial ] % 0 : $ * StructWithLazyProperty <nl> + % 18 = apply % 7 ( % 0 ) : $ @ convention ( method ) ( @ inout StructWithLazyProperty ) - > Int64 <nl> + % 20 = apply % 9 ( % 18 ) : $ @ convention ( thin ) ( Int64 ) - > ( ) <nl> + dealloc_stack % 0 : $ * StructWithLazyProperty <nl> + % 22 = tuple ( ) <nl> + return % 22 : $ ( ) <nl> + } <nl> + <nl> new file mode 100644 <nl> index 000000000000 . . 88cb89feeb8f <nl> mmm / dev / null <nl> ppp b / test / SILOptimizer / cse_ossa_nontrivial . sil <nl> <nl> + / / RUN : % target - sil - opt - enable - sil - verify - all % s - cse | % FileCheck % s <nl> + sil_stage canonical <nl> + <nl> + import Builtin <nl> + import Swift <nl> + <nl> + / / / / / / / / / / / / / / / <nl> + / / CSE Tests / / <nl> + / / / / / / / / / / / / / / / <nl> + class Klass { <nl> + } <nl> + <nl> + struct NonTrivialStruct { <nl> + var val : Klass <nl> + } <nl> + <nl> + public enum FakeOptional { <nl> + case none <nl> + case some ( Klass ) <nl> + } <nl> + <nl> + public enum FakeOptional2 { <nl> + case some1 ( UInt ) <nl> + case some2 ( Klass ) <nl> + } <nl> + <nl> + struct StructWithEnum { <nl> + var val : FakeOptional <nl> + } <nl> + <nl> + struct StructWithEnum2 { <nl> + var val : FakeOptional2 <nl> + } <nl> + <nl> + sil @ use_nontrivialstruct1 : $ @ convention ( thin ) ( @ guaranteed NonTrivialStruct ) - > ( ) <nl> + sil @ use_nontrivialstruct2 : $ @ convention ( thin ) ( @ owned NonTrivialStruct ) - > ( ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ structliteral1 : <nl> + / / CHECK : struct $ NonTrivialStruct <nl> + / / CHECK - NOT : struct $ NonTrivialStruct <nl> + / / CHECK - LABEL : } / / end sil function ' structliteral1 ' <nl> + sil [ ossa ] @ structliteral1 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % 2 = struct $ NonTrivialStruct ( % 0 : $ Klass ) <nl> + % 3 = struct $ NonTrivialStruct ( % 0 : $ Klass ) <nl> + % 5 = function_ref @ use_nontrivialstruct1 : $ @ convention ( thin ) ( @ guaranteed NonTrivialStruct ) - > ( ) <nl> + apply % 5 ( % 2 ) : $ @ convention ( thin ) ( @ guaranteed NonTrivialStruct ) - > ( ) <nl> + apply % 5 ( % 3 ) : $ @ convention ( thin ) ( @ guaranteed NonTrivialStruct ) - > ( ) <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ structliteral2 : <nl> + / / CHECK : struct $ NonTrivialStruct <nl> + / / CHECK - NOT : struct $ NonTrivialStruct <nl> + / / CHECK - LABEL : } / / end sil function ' structliteral2 ' <nl> + sil [ ossa ] @ structliteral2 : $ @ convention ( thin ) ( @ owned Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 2 = struct $ NonTrivialStruct ( % 0 : $ Klass ) <nl> + % 3 = struct $ NonTrivialStruct ( % copy0 : $ Klass ) <nl> + % 5 = function_ref @ use_nontrivialstruct2 : $ @ convention ( thin ) ( @ owned NonTrivialStruct ) - > ( ) <nl> + apply % 5 ( % 2 ) : $ @ convention ( thin ) ( @ owned NonTrivialStruct ) - > ( ) <nl> + apply % 5 ( % 3 ) : $ @ convention ( thin ) ( @ owned NonTrivialStruct ) - > ( ) <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + sil [ ossa ] @ sadd_with_address : $ @ convention ( thin ) ( @ inout Klass , @ inout Klass ) - > ( Klass ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ project_box_test1 : <nl> + / / CHECK : project_box % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > <nl> + / / CHECK - NOT : project_box <nl> + / / CHECK - LABEL : } / / end sil function ' project_box_test1 ' <nl> + sil [ ossa ] @ project_box_test1 : $ ( @ owned < τ_0_0 > { var τ_0_0 } < Klass > ) - > Klass { <nl> + bb0 ( % 0 : @ owned $ < τ_0_0 > { var τ_0_0 } < Klass > ) : <nl> + % 1 = project_box % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > , 0 <nl> + % 2 = project_box % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > , 0 <nl> + % 3 = function_ref @ sadd_with_address : $ @ convention ( thin ) ( @ inout Klass , @ inout Klass ) - > ( Klass ) <nl> + % 4 = apply % 3 ( % 1 , % 2 ) : $ @ convention ( thin ) ( @ inout Klass , @ inout Klass ) - > ( Klass ) <nl> + destroy_value % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > <nl> + return % 4 : $ ( Klass ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ project_box_test2 : <nl> + / / CHECK : project_box % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > <nl> + / / CHECK - NOT : project_box <nl> + / / CHECK - LABEL : } / / end sil function ' project_box_test2 ' <nl> + sil [ ossa ] @ project_box_test2 : $ ( @ owned < τ_0_0 > { var τ_0_0 } < Klass > ) - > Klass { <nl> + bb0 ( % 0 : @ owned $ < τ_0_0 > { var τ_0_0 } < Klass > ) : <nl> + % 1 = project_box % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > , 0 <nl> + % copy0 = copy_value % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > <nl> + % 2 = project_box % copy0 : $ < τ_0_0 > { var τ_0_0 } < Klass > , 0 <nl> + % 3 = function_ref @ sadd_with_address : $ @ convention ( thin ) ( @ inout Klass , @ inout Klass ) - > ( Klass ) <nl> + % 4 = apply % 3 ( % 1 , % 2 ) : $ @ convention ( thin ) ( @ inout Klass , @ inout Klass ) - > ( Klass ) <nl> + destroy_value % copy0 : $ < τ_0_0 > { var τ_0_0 } < Klass > <nl> + destroy_value % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > <nl> + return % 4 : $ ( Klass ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ project_box_test3 : <nl> + / / CHECK : project_box <nl> + / / CHECK - NOT : project_box <nl> + / / CHECK - LABEL : } / / end sil function ' project_box_test3 ' <nl> + sil [ ossa ] @ project_box_test3 : $ ( @ owned < τ_0_0 > { var τ_0_0 } < Klass > ) - > Klass { <nl> + bb0 ( % 0 : @ owned $ < τ_0_0 > { var τ_0_0 } < Klass > ) : <nl> + % copy0 = copy_value % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > <nl> + % 2 = project_box % copy0 : $ < τ_0_0 > { var τ_0_0 } < Klass > , 0 <nl> + % 1 = project_box % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > , 0 <nl> + % 3 = function_ref @ sadd_with_address : $ @ convention ( thin ) ( @ inout Klass , @ inout Klass ) - > ( Klass ) <nl> + % 4 = apply % 3 ( % 1 , % 2 ) : $ @ convention ( thin ) ( @ inout Klass , @ inout Klass ) - > ( Klass ) <nl> + destroy_value % copy0 : $ < τ_0_0 > { var τ_0_0 } < Klass > <nl> + destroy_value % 0 : $ < τ_0_0 > { var τ_0_0 } < Klass > <nl> + return % 4 : $ ( Klass ) <nl> + } <nl> + <nl> + sil [ ossa ] @ tuple_function1 : $ @ convention ( thin ) ( @ owned ( Klass , Klass ) , @ owned ( Klass , Klass ) ) - > @ owned ( Klass ) <nl> + sil [ ossa ] @ tuple_function2 : $ @ convention ( thin ) ( @ guaranteed ( Klass , Klass ) , @ guaranteed ( Klass , Klass ) ) - > @ owned ( Klass ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ tuple_test1 : <nl> + / / CHECK : tuple ( { { % [ 0 - 9 ] + } } : $ Klass , { { % [ 0 - 9 ] + } } : $ Klass ) <nl> + / / CHECK - NOT : tuple ( { { % [ 0 - 9 ] + } } : $ Klass , { { % [ 0 - 9 ] + } } : $ Klass ) <nl> + / / CHECK - LABEL : } / / end sil function ' tuple_test1 ' <nl> + sil [ ossa ] @ tuple_test1 : $ @ convention ( thin ) ( @ owned Klass , @ owned Klass ) - > @ owned ( Klass ) { <nl> + bb0 ( % 0 : @ owned $ Klass , % 1 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % copy1 = copy_value % 1 : $ Klass <nl> + % 2 = tuple ( % 0 : $ Klass , % 1 : $ Klass ) <nl> + % 3 = tuple ( % copy0 : $ Klass , % copy1 : $ Klass ) <nl> + % 4 = function_ref @ tuple_function1 : $ @ convention ( thin ) ( @ owned ( Klass , Klass ) , @ owned ( Klass , Klass ) ) - > @ owned ( Klass ) <nl> + % 5 = apply % 4 ( % 2 , % 3 ) : $ @ convention ( thin ) ( @ owned ( Klass , Klass ) , @ owned ( Klass , Klass ) ) - > @ owned ( Klass ) <nl> + return % 5 : $ ( Klass ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ tuple_test2 : <nl> + / / CHECK : tuple ( { { % [ 0 - 9 ] + } } : $ Klass , { { % [ 0 - 9 ] + } } : $ Klass ) <nl> + / / CHECK - NOT : tuple ( { { % [ 0 - 9 ] + } } : $ Klass , { { % [ 0 - 9 ] + } } : $ Klass ) <nl> + / / CHECK - LABEL : } / / end sil function ' tuple_test2 ' <nl> + sil [ ossa ] @ tuple_test2 : $ @ convention ( thin ) ( @ guaranteed Klass , @ guaranteed Klass ) - > @ owned ( Klass ) { <nl> + bb0 ( % 0 : @ guaranteed $ Klass , % 1 : @ guaranteed $ Klass ) : <nl> + % 2 = tuple ( % 0 : $ Klass , % 1 : $ Klass ) <nl> + % 3 = tuple ( % 0 : $ Klass , % 1 : $ Klass ) <nl> + % 4 = function_ref @ tuple_function2 : $ @ convention ( thin ) ( @ guaranteed ( Klass , Klass ) , @ guaranteed ( Klass , Klass ) ) - > @ owned ( Klass ) <nl> + % 5 = apply % 4 ( % 2 , % 3 ) : $ @ convention ( thin ) ( @ guaranteed ( Klass , Klass ) , @ guaranteed ( Klass , Klass ) ) - > @ owned ( Klass ) <nl> + return % 5 : $ ( Klass ) <nl> + } <nl> + <nl> + sil [ ossa ] @ generate_tuple : $ @ convention ( thin ) ( ) - > @ owned ( ( Klass , Klass ) ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ tupleextract_test : <nl> + / / CHECK : tuple_extract { { % [ 0 - 9 ] } } : $ ( Klass , Klass ) , 0 <nl> + / / CHECK - NOT : tuple_extract { { % [ 0 - 9 ] } } : $ ( Klass , Klass ) , 0 <nl> + / / CHECK - LABEL : } / / end sil function ' tupleextract_test ' <nl> + sil [ ossa ] @ tupleextract_test : $ @ convention ( thin ) ( ) - > @ owned ( Klass ) { <nl> + % 0 = function_ref @ generate_tuple : $ @ convention ( thin ) ( ) - > @ owned ( ( Klass , Klass ) ) <nl> + % 1 = apply % 0 ( ) : $ @ convention ( thin ) ( ) - > @ owned ( ( Klass , Klass ) ) <nl> + % borrow1 = begin_borrow % 1 : $ ( Klass , Klass ) <nl> + % 2 = tuple_extract % borrow1 : $ ( Klass , Klass ) , 0 <nl> + % 3 = tuple_extract % borrow1 : $ ( Klass , Klass ) , 0 <nl> + % 5 = integer_literal $ Builtin . Int1 , 0 <nl> + % 6 = builtin " sadd_with_overflow_Int32 " ( % 2 : $ Klass , % 3 : $ Klass , % 5 : $ Builtin . Int1 ) : $ ( Klass , Builtin . Int1 ) <nl> + % 7 = tuple_extract % 6 : $ ( Klass , Builtin . Int1 ) , 0 <nl> + end_borrow % borrow1 : $ ( Klass , Klass ) <nl> + destroy_value % 1 : $ ( Klass , Klass ) <nl> + return % 7 : $ ( Klass ) <nl> + } <nl> + <nl> + sil [ ossa ] @ helper : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . RawPointer ) - > Builtin . Word <nl> + sil [ ossa ] @ helper2 : $ @ convention ( thin ) ( UInt8 , UInt8 ) - > Builtin . Word <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ enum_cse : <nl> + / / CHECK : enum $ FakeOptional , # FakeOptional . none ! enumelt <nl> + / / CHECK - NOT : enum $ FakeOptional , # FakeOptional . none ! enumelt <nl> + / / CHECK : enum $ FakeOptional , # FakeOptional . some ! enumelt <nl> + / / CHECK - NOT : enum $ FakeOptional , # FakeOptional . some ! enumelt <nl> + / / CHECK - LABEL : } / / end sil function ' enum_cse ' <nl> + sil [ ossa ] @ unknown_fake_optional_user : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + sil [ ossa ] @ enum_cse : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % func = function_ref @ unknown_fake_optional_user : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + % 1 = enum $ FakeOptional , # FakeOptional . none ! enumelt <nl> + % 2 = enum $ FakeOptional , # FakeOptional . none ! enumelt <nl> + apply % func ( % 1 ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + apply % func ( % 2 ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + % 4 = enum $ FakeOptional , # FakeOptional . some ! enumelt , % 0 : $ Klass <nl> + % 5 = enum $ FakeOptional , # FakeOptional . some ! enumelt , % 0 : $ Klass <nl> + apply % func ( % 4 ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + apply % func ( % 5 ) : $ @ convention ( thin ) ( FakeOptional ) - > ( ) <nl> + % 6 = tuple ( ) <nl> + return % 6 : $ ( ) <nl> + } <nl> + <nl> + sil [ ossa ] @ klass_user : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ unchecked_enum_data_cse : <nl> + / / CHECK : unchecked_enum_data <nl> + / / CHECK - NOT : unchecked_enum_data <nl> + / / CHECK - LABEL : } / / end sil function ' unchecked_enum_data_cse ' <nl> + sil [ ossa ] @ unchecked_enum_data_cse : $ @ convention ( thin ) ( @ guaranteed FakeOptional ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ FakeOptional ) : <nl> + % 1 = function_ref @ klass_user : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) <nl> + % 2 = unchecked_enum_data % 0 : $ FakeOptional , # FakeOptional . some ! enumelt <nl> + % 3 = unchecked_enum_data % 0 : $ FakeOptional , # FakeOptional . some ! enumelt <nl> + apply % 1 ( % 2 ) : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) <nl> + apply % 1 ( % 3 ) : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) <nl> + % 6 = tuple ( ) <nl> + return % 6 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ test2cse1 : <nl> + / / CHECK : ref_to_raw_pointer <nl> + / / CHECK - NOT : ref_to_raw_pointer <nl> + / / CHECK : function_ref <nl> + / / CHECK : apply <nl> + / / CHECK - LABEL : } / / end sil function ' test2cse1 ' <nl> + sil [ ossa ] @ test2cse1 : $ @ convention ( thin ) ( @ owned Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % 1 = ref_to_raw_pointer % 0 : $ Klass to $ Builtin . RawPointer <nl> + % 2 = ref_to_raw_pointer % 0 : $ Klass to $ Builtin . RawPointer <nl> + % 4 = function_ref @ helper : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . RawPointer ) - > Builtin . Word <nl> + % 5 = apply % 4 ( % 1 , % 2 ) : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . RawPointer ) - > Builtin . Word <nl> + destroy_value % 0 : $ Klass <nl> + % 6 = tuple ( ) <nl> + return % 6 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ test2cse2 : <nl> + / / CHECK : ref_to_raw_pointer <nl> + / / CHECK - NOT : ref_to_raw_pointer <nl> + / / CHECK : function_ref <nl> + / / CHECK : apply <nl> + / / CHECK - LABEL : } / / end sil function ' test2cse2 ' <nl> + sil [ ossa ] @ test2cse2 : $ @ convention ( thin ) ( @ owned Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = ref_to_raw_pointer % 0 : $ Klass to $ Builtin . RawPointer <nl> + % 2 = ref_to_raw_pointer % copy0 : $ Klass to $ Builtin . RawPointer <nl> + % 4 = function_ref @ helper : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . RawPointer ) - > Builtin . Word <nl> + % 5 = apply % 4 ( % 1 , % 2 ) : $ @ convention ( thin ) ( Builtin . RawPointer , Builtin . RawPointer ) - > Builtin . Word <nl> + destroy_value % copy0 : $ Klass <nl> + destroy_value % 0 : $ Klass <nl> + % 6 = tuple ( ) <nl> + return % 6 : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_raw_pointer_to_ref : <nl> + / / CHECK : raw_pointer_to_ref <nl> + / / CHECK - NOT : raw_pointer_to_ref <nl> + / / CHECK : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' cse_raw_pointer_to_ref ' <nl> + sil [ ossa ] @ cse_raw_pointer_to_ref : $ @ convention ( thin ) ( Builtin . RawPointer ) - > ( Klass , Klass ) { <nl> + bb0 ( % 0 : $ Builtin . RawPointer ) : <nl> + % 1 = raw_pointer_to_ref % 0 : $ Builtin . RawPointer to $ Klass <nl> + % 2 = raw_pointer_to_ref % 0 : $ Builtin . RawPointer to $ Klass <nl> + % 6 = tuple ( % 1 : $ Klass , % 2 : $ Klass ) <nl> + return % 6 : $ ( Klass , Klass ) <nl> + } <nl> + <nl> + enum Enum1 { <nl> + case Case1 <nl> + case Case2 <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_select_enum : <nl> + / / CHECK : select_enum <nl> + / / CHECK - NOT : select_enum <nl> + / / CHECK : tuple <nl> + / / CHECK - LABEL : } / / end sil function ' cse_select_enum ' <nl> + sil [ ossa ] @ cse_select_enum : $ @ convention ( thin ) ( @ guaranteed Enum1 ) - > ( Builtin . Int1 , Builtin . Int1 ) { <nl> + bb0 ( % 0 : $ Enum1 ) : <nl> + % t = integer_literal $ Builtin . Int1 , 1 <nl> + % f = integer_literal $ Builtin . Int1 , 0 <nl> + % 1 = select_enum % 0 : $ Enum1 , case # Enum1 . Case1 ! enumelt : % t , case # Enum1 . Case2 ! enumelt : % f : $ Builtin . Int1 <nl> + % 2 = select_enum % 0 : $ Enum1 , case # Enum1 . Case1 ! enumelt : % t , case # Enum1 . Case2 ! enumelt : % f : $ Builtin . Int1 <nl> + % 3 = tuple ( % 1 : $ Builtin . Int1 , % 2 : $ Builtin . Int1 ) <nl> + return % 3 : $ ( Builtin . Int1 , Builtin . Int1 ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_bridge_object_to_word1 : <nl> + / / CHECK : [ [ REF : % [ 0 - 9 ] + ] ] = bridge_object_to_word <nl> + / / CHECK - NOT : bridge_object_to_word <nl> + / / CHECK : tuple ( [ [ REF ] ] : $ Builtin . Word , [ [ REF ] ] : $ Builtin . Word ) <nl> + / / CHECK - LABEL : } / / end sil function ' cse_bridge_object_to_word1 ' <nl> + sil [ ossa ] @ cse_bridge_object_to_word1 : $ @ convention ( thin ) ( @ owned Builtin . BridgeObject ) - > ( Builtin . Word , Builtin . Word ) { <nl> + bb0 ( % 0 : @ owned $ Builtin . BridgeObject ) : <nl> + % 1 = bridge_object_to_word % 0 : $ Builtin . BridgeObject to $ Builtin . Word <nl> + % 2 = bridge_object_to_word % 0 : $ Builtin . BridgeObject to $ Builtin . Word <nl> + % 3 = tuple ( % 1 : $ Builtin . Word , % 2 : $ Builtin . Word ) <nl> + destroy_value % 0 : $ Builtin . BridgeObject <nl> + return % 3 : $ ( Builtin . Word , Builtin . Word ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_bridge_object_to_word2 : <nl> + / / CHECK : [ [ REF : % [ 0 - 9 ] + ] ] = bridge_object_to_word <nl> + / / CHECK - NOT : bridge_object_to_word <nl> + / / CHECK : tuple ( [ [ REF ] ] : $ Builtin . Word , [ [ REF ] ] : $ Builtin . Word ) <nl> + / / CHECK - LABEL : } / / end sil function ' cse_bridge_object_to_word2 ' <nl> + sil [ ossa ] @ cse_bridge_object_to_word2 : $ @ convention ( thin ) ( @ owned Builtin . BridgeObject ) - > ( Builtin . Word , Builtin . Word ) { <nl> + bb0 ( % 0 : @ owned $ Builtin . BridgeObject ) : <nl> + % copy = copy_value % 0 : $ Builtin . BridgeObject <nl> + % 1 = bridge_object_to_word % 0 : $ Builtin . BridgeObject to $ Builtin . Word <nl> + % 2 = bridge_object_to_word % copy : $ Builtin . BridgeObject to $ Builtin . Word <nl> + % 3 = tuple ( % 1 : $ Builtin . Word , % 2 : $ Builtin . Word ) <nl> + destroy_value % copy : $ Builtin . BridgeObject <nl> + destroy_value % 0 : $ Builtin . BridgeObject <nl> + return % 3 : $ ( Builtin . Word , Builtin . Word ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ cse_bridge_object_to_word3 : <nl> + / / CHECK : [ [ REF : % [ 0 - 9 ] + ] ] = bridge_object_to_word <nl> + / / CHECK - NOT : bridge_object_to_word <nl> + / / CHECK : tuple ( [ [ REF ] ] : $ Builtin . Word , [ [ REF ] ] : $ Builtin . Word ) <nl> + / / CHECK - LABEL : } / / end sil function ' cse_bridge_object_to_word3 ' <nl> + sil [ ossa ] @ cse_bridge_object_to_word3 : $ @ convention ( thin ) ( @ owned Builtin . BridgeObject ) - > ( Builtin . Word , Builtin . Word ) { <nl> + bb0 ( % 0 : @ owned $ Builtin . BridgeObject ) : <nl> + % copy = copy_value % 0 : $ Builtin . BridgeObject <nl> + % 2 = bridge_object_to_word % copy : $ Builtin . BridgeObject to $ Builtin . Word <nl> + % 1 = bridge_object_to_word % 0 : $ Builtin . BridgeObject to $ Builtin . Word <nl> + % 3 = tuple ( % 1 : $ Builtin . Word , % 2 : $ Builtin . Word ) <nl> + destroy_value % copy : $ Builtin . BridgeObject <nl> + destroy_value % 0 : $ Builtin . BridgeObject <nl> + return % 3 : $ ( Builtin . Word , Builtin . Word ) <nl> + } <nl> + <nl> + class Ping { <nl> + func ping ( ) - > Ping <nl> + } <nl> + sil [ ossa ] @ _TFC4main4Ping4pingfS0_FT_S0_ : $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + sil [ ossa ] @ _TFC4main4PingD : $ @ convention ( method ) ( @ owned Ping ) - > ( ) <nl> + sil [ ossa ] @ _TFC4main4PingcfMS0_FT_S0_ : $ @ convention ( method ) ( @ owned Ping ) - > @ owned Ping <nl> + <nl> + / / TODO : In order to cse this , we have to handle class_method with copy_value in InstructionIdentityComparer <nl> + / / CHECK - LABEL : sil [ ossa ] @ _TF4main4ringFCS_4PingT_ : <nl> + / / CHECK : class_method <nl> + / / CHECK : class_method <nl> + / / CHECK - LABEL : } / / end sil function ' _TF4main4ringFCS_4PingT_ ' <nl> + sil [ ossa ] @ _TF4main4ringFCS_4PingT_ : $ @ convention ( thin ) ( @ owned Ping ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ Ping ) : <nl> + % copy0 = copy_value % 0 : $ Ping <nl> + % 1 = class_method % 0 : $ Ping , # Ping . ping : ( Ping ) - > ( ) - > Ping , $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 1a = class_method % copy0 : $ Ping , # Ping . ping : ( Ping ) - > ( ) - > Ping , $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 2 = apply % 1 ( % 0 ) : $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + % 2a = apply % 1a ( % 0 ) : $ @ convention ( method ) ( @ guaranteed Ping ) - > @ owned Ping <nl> + destroy_value % 2 : $ Ping <nl> + destroy_value % 2a : $ Ping <nl> + destroy_value % copy0 : $ Ping <nl> + destroy_value % 0 : $ Ping <nl> + % 10 = tuple ( ) <nl> + return % 10 : $ ( ) <nl> + } <nl> + <nl> + sil_vtable Ping { <nl> + # Ping . ping : @ _TFC4main4Ping4pingfS0_FT_S0_ / / main . Ping . ping ( main . Ping ) ( ) - > main . Ping <nl> + # Ping . deinit ! deallocator : @ _TFC4main4PingD / / main . Ping . __deallocating_deinit <nl> + # Ping . init ! initializer : @ _TFC4main4PingcfMS0_FT_S0_ / / main . Ping . init ( main . Ping . Type ) ( ) - > main . Ping <nl> + } <nl> + <nl> + struct KlassPair { <nl> + var first : Klass <nl> + var second : Klass <nl> + } <nl> + <nl> + / / Support destructure_struct in CSE after introducing support for MultipleValueInstruction is OSSA ' s rauw utility <nl> + / / CHECK - LABEL : sil [ ossa ] @ destructure_struct_test1 : <nl> + / / CHECK : destructure_struct <nl> + / / TODOCHECK - NOT : destructure_struct <nl> + / / CHECK - LABEL : } / / end sil function ' destructure_struct_test1 ' <nl> + sil [ ossa ] @ destructure_struct_test1 : $ @ convention ( thin ) ( @ owned KlassPair ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ KlassPair ) : <nl> + % copy0 = copy_value % 0 : $ KlassPair <nl> + ( % 1 , % 2 ) = destructure_struct % 0 : $ KlassPair <nl> + ( % 3 , % 4 ) = destructure_struct % copy0 : $ KlassPair <nl> + destroy_value % 1 : $ Klass <nl> + destroy_value % 2 : $ Klass <nl> + destroy_value % 3 : $ Klass <nl> + destroy_value % 4 : $ Klass <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + / / Support destructure_struct in CSE after introducing support for MultipleValueInstruction is OSSA ' s rauw utility <nl> + / / CHECK - LABEL : sil [ ossa ] @ destructure_struct_test2 : <nl> + / / CHECK : destructure_struct <nl> + / / TODOCHECK - NOT : destructure_struct <nl> + / / CHECK - LABEL : } / / end sil function ' destructure_struct_test2 ' <nl> + sil [ ossa ] @ destructure_struct_test2 : $ @ convention ( thin ) ( @ guaranteed KlassPair ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ KlassPair ) : <nl> + ( % 1 , % 2 ) = destructure_struct % 0 : $ KlassPair <nl> + ( % 3 , % 4 ) = destructure_struct % 0 : $ KlassPair <nl> + % func = function_ref @ klass_user : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) <nl> + apply % func ( % 2 ) : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) <nl> + apply % func ( % 3 ) : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + / / Support destructure_tuple in CSE after introducing support for MultipleValueInstruction is OSSA ' s rauw utility <nl> + / / CHECK - LABEL : sil [ ossa ] @ destructure_tuple_test1 : <nl> + / / CHECK : destructure_tuple <nl> + / / TODOCHECK - NOT : destructure_tuple <nl> + / / CHECK - LABEL : } / / end sil function ' destructure_tuple_test1 ' <nl> + sil [ ossa ] @ destructure_tuple_test1 : $ @ convention ( thin ) ( @ owned ( Klass , Klass ) ) - > ( ) { <nl> + bb0 ( % 0 : @ owned $ ( Klass , Klass ) ) : <nl> + % copy0 = copy_value % 0 : $ ( Klass , Klass ) <nl> + ( % 1 , % 2 ) = destructure_tuple % 0 : $ ( Klass , Klass ) <nl> + ( % 3 , % 4 ) = destructure_tuple % copy0 : $ ( Klass , Klass ) <nl> + destroy_value % 1 : $ Klass <nl> + destroy_value % 2 : $ Klass <nl> + destroy_value % 3 : $ Klass <nl> + destroy_value % 4 : $ Klass <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + / / Support destructure_tuple in CSE after introducing support for MultipleValueInstruction is OSSA ' s rauw utility <nl> + / / CHECK - LABEL : sil [ ossa ] @ destructure_tuple_test2 : <nl> + / / CHECK : destructure_tuple <nl> + / / TODOCHECK - NOT : destructure_tuple <nl> + / / CHECK - LABEL : } / / end sil function ' destructure_tuple_test2 ' <nl> + sil [ ossa ] @ destructure_tuple_test2 : $ @ convention ( thin ) ( @ guaranteed ( Klass , Klass ) ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ ( Klass , Klass ) ) : <nl> + ( % 1 , % 2 ) = destructure_tuple % 0 : $ ( Klass , Klass ) <nl> + ( % 3 , % 4 ) = destructure_tuple % 0 : $ ( Klass , Klass ) <nl> + % func = function_ref @ klass_user : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) <nl> + apply % func ( % 2 ) : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) <nl> + apply % func ( % 3 ) : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ struct_test2 : <nl> + / / CHECK : struct $ NonTrivialStruct <nl> + / / CHECK - NOT : struct $ NonTrivialStruct <nl> + / / CHECK - LABEL : } / / end sil function ' struct_test2 ' <nl> + sil [ ossa ] @ struct_test2 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > @ owned Klass { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = struct $ NonTrivialStruct ( % copy0 : $ Klass ) <nl> + % 2 = struct $ NonTrivialStruct ( % 0 : $ Klass ) <nl> + % 3 = struct_extract % 2 : $ NonTrivialStruct , # NonTrivialStruct . val <nl> + destroy_value % 1 : $ NonTrivialStruct <nl> + % copy3 = copy_value % 3 : $ Klass <nl> + return % copy3 : $ Klass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ struct_test3 : <nl> + / / CHECK : struct $ NonTrivialStruct <nl> + / / CHECK - NOT : struct $ NonTrivialStruct <nl> + / / CHECK - LABEL : } / / end sil function ' struct_test3 ' <nl> + sil [ ossa ] @ struct_test3 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 1 = struct $ NonTrivialStruct ( % copy0 : $ Klass ) <nl> + % 2 = struct $ NonTrivialStruct ( % 0 : $ Klass ) <nl> + % 3 = struct_extract % 2 : $ NonTrivialStruct , # NonTrivialStruct . val <nl> + destroy_value % 1 : $ NonTrivialStruct <nl> + % copy3 = copy_value % 3 : $ Klass <nl> + destroy_value % copy3 : $ Klass <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ struct_test4 : <nl> + / / CHECK : struct $ NonTrivialStruct <nl> + / / CHECK - NOT : struct $ NonTrivialStruct <nl> + / / CHECK - LABEL : } / / end sil function ' struct_test4 ' <nl> + sil [ ossa ] @ struct_test4 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % 1 = struct $ NonTrivialStruct ( % 0 : $ Klass ) <nl> + % 2 = struct $ NonTrivialStruct ( % 0 : $ Klass ) <nl> + % 3 = struct_extract % 2 : $ NonTrivialStruct , # NonTrivialStruct . val <nl> + % 4 = struct_extract % 1 : $ NonTrivialStruct , # NonTrivialStruct . val <nl> + % copy3 = copy_value % 3 : $ Klass <nl> + % copy4 = copy_value % 4 : $ Klass <nl> + destroy_value % copy3 : $ Klass <nl> + destroy_value % copy4 : $ Klass <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ struct_test5 : <nl> + / / CHECK : struct $ NonTrivialStruct <nl> + / / CHECK - NOT : struct $ NonTrivialStruct <nl> + / / CHECK - LABEL : } / / end sil function ' struct_test5 ' <nl> + sil [ ossa ] @ struct_test5 : $ @ convention ( thin ) ( @ guaranteed Klass ) - > @ owned Klass { <nl> + bb0 ( % 0 : @ guaranteed $ Klass ) : <nl> + % copy0 = copy_value % 0 : $ Klass <nl> + % 2 = struct $ NonTrivialStruct ( % 0 : $ Klass ) <nl> + % 1 = struct $ NonTrivialStruct ( % copy0 : $ Klass ) <nl> + % 3 = struct_extract % 2 : $ NonTrivialStruct , # NonTrivialStruct . val <nl> + destroy_value % 1 : $ NonTrivialStruct <nl> + % copy3 = copy_value % 3 : $ Klass <nl> + return % copy3 : $ Klass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ struct_extract_test1 : <nl> + / / CHECK : struct_extract <nl> + / / CHECK - NOT : struct_extract <nl> + / / CHECK - LABEL : } / / end sil function ' struct_extract_test1 ' <nl> + sil [ ossa ] @ struct_extract_test1 : $ @ convention ( thin ) ( @ owned NonTrivialStruct ) - > @ owned Klass { <nl> + bb0 ( % 0 : @ owned $ NonTrivialStruct ) : <nl> + % borrow0 = begin_borrow % 0 : $ NonTrivialStruct <nl> + % 2 = struct_extract % borrow0 : $ NonTrivialStruct , # NonTrivialStruct . val <nl> + % copy2 = copy_value % 2 : $ Klass <nl> + end_borrow % borrow0 : $ NonTrivialStruct <nl> + % borrow1 = begin_borrow % 0 : $ NonTrivialStruct <nl> + % 3 = struct_extract % borrow1 : $ NonTrivialStruct , # NonTrivialStruct . val <nl> + % copy3 = copy_value % 3 : $ Klass <nl> + end_borrow % borrow1 : $ NonTrivialStruct <nl> + destroy_value % copy2 : $ Klass <nl> + destroy_value % 0 : $ NonTrivialStruct <nl> + return % copy3 : $ Klass <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ struct_extract_test2 : <nl> + / / CHECK : struct_extract <nl> + / / CHECK - NOT : struct_extract <nl> + / / CHECK - LABEL : } / / end sil function ' struct_extract_test2 ' <nl> + sil [ ossa ] @ struct_extract_test2 : $ @ convention ( thin ) ( @ guaranteed NonTrivialStruct ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ NonTrivialStruct ) : <nl> + % 1 = struct_extract % 0 : $ NonTrivialStruct , # NonTrivialStruct . val <nl> + % copy1 = copy_value % 1 : $ Klass <nl> + % 2 = struct_extract % 0 : $ NonTrivialStruct , # NonTrivialStruct . val <nl> + % copy2 = copy_value % 2 : $ Klass <nl> + destroy_value % copy1 : $ Klass <nl> + destroy_value % copy2 : $ Klass <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil [ ossa ] @ struct_extract_test3 : <nl> + / / CHECK : struct_extract <nl> + / / CHECK - NOT : struct_extract <nl> + / / CHECK - LABEL : } / / end sil function ' struct_extract_test3 ' <nl> + sil [ ossa ] @ struct_extract_test3 : $ @ convention ( thin ) ( @ guaranteed StructWithEnum ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ StructWithEnum ) : <nl> + % 1 = struct_extract % 0 : $ StructWithEnum , # StructWithEnum . val <nl> + % copy1 = copy_value % 1 : $ FakeOptional <nl> + switch_enum % 1 : $ FakeOptional , case # FakeOptional . some ! enumelt : bb1 , case # FakeOptional . none ! enumelt : bb2 <nl> + <nl> + bb1 ( % arg1 : @ guaranteed $ Klass ) : <nl> + br bb3 <nl> + <nl> + bb2 : <nl> + br bb3 <nl> + <nl> + bb3 : <nl> + % 2 = struct_extract % 0 : $ StructWithEnum , # StructWithEnum . val <nl> + % copy2 = copy_value % 2 : $ FakeOptional <nl> + switch_enum % 2 : $ FakeOptional , case # FakeOptional . some ! enumelt : bb4 , case # FakeOptional . none ! enumelt : bb5 <nl> + <nl> + bb4 ( % arg2 : @ guaranteed $ Klass ) : <nl> + br bb6 <nl> + <nl> + bb5 : <nl> + br bb6 <nl> + <nl> + bb6 : <nl> + destroy_value % copy1 : $ FakeOptional <nl> + destroy_value % copy2 : $ FakeOptional <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl> + / / This CSE test will need the OSSA rauw utility to split edges <nl> + / / CHECK - LABEL : sil [ ossa ] @ struct_extract_test4 : <nl> + / / CHECK : struct_extract <nl> + / / CHECK - NOT : struct_extract <nl> + / / CHECK - LABEL : } / / end sil function ' struct_extract_test4 ' <nl> + sil [ ossa ] @ struct_extract_test4 : $ @ convention ( thin ) ( @ guaranteed StructWithEnum2 ) - > ( ) { <nl> + bb0 ( % 0 : @ guaranteed $ StructWithEnum2 ) : <nl> + % 1 = struct_extract % 0 : $ StructWithEnum2 , # StructWithEnum2 . val <nl> + % copy1 = copy_value % 1 : $ FakeOptional2 <nl> + br bb4 <nl> + <nl> + bb4 : <nl> + % 2 = struct_extract % 0 : $ StructWithEnum2 , # StructWithEnum2 . val <nl> + % copy2 = copy_value % 2 : $ FakeOptional2 <nl> + switch_enum % 2 : $ FakeOptional2 , case # FakeOptional2 . some1 ! enumelt : bb5 , case # FakeOptional2 . some2 ! enumelt : bb6 <nl> + <nl> + bb5 ( % arg4 : $ UInt ) : <nl> + br bb7 ( % arg4 : $ UInt ) <nl> + <nl> + bb6 ( % arg5 : @ guaranteed $ Klass ) : <nl> + % 4 = unchecked_trivial_bit_cast % arg5 : $ Klass to $ UInt <nl> + br bb7 ( % 4 : $ UInt ) <nl> + <nl> + bb7 ( % arg6 : $ UInt ) : <nl> + destroy_value % copy2 : $ FakeOptional2 <nl> + br bb8 <nl> + <nl> + bb8 : <nl> + destroy_value % copy1 : $ FakeOptional2 <nl> + % res = tuple ( ) <nl> + return % res : $ ( ) <nl> + } <nl> + <nl>
Enable CSE on OSSA
apple/swift
42c031985cc93a350abfa47e64898efe064e23a5
2020-12-23T07:20:06Z
mmm a / PRESUBMIT . py <nl> ppp b / PRESUBMIT . py <nl> def _CommonChecks ( input_api , output_api ) : <nl> def _SkipTreeCheck ( input_api , output_api ) : <nl> " " " Check the env var whether we want to skip tree check . <nl> Only skip if src / version . cc has been updated . " " " <nl> + print " skip tree check ? " , input_api . environ . get ( ' PRESUBMIT_TREE_CHECK ' ) <nl> src_version = ' src / version . cc ' <nl> - FilterFile = lambda file : file . LocalPath ( ) = = src_version <nl> - if not input_api . AffectedSourceFiles ( <nl> - lambda file : file . LocalPath ( ) = = src_version ) : <nl> + def FilterFile ( file ) : <nl> + print " Changed file : " , file . LocalPath ( ) <nl> + return file . LocalPath ( ) = = src_version <nl> + if not input_api . AffectedSourceFiles ( FilterFile ) : <nl> return False <nl> if input_api . environ . get ( ' PRESUBMIT_TREE_CHECK ' ) = = ' skip ' : <nl> print " Skip tree check requested via environment variable . " <nl>
Add more temporary debugging output to PRESUBMIT . py
v8/v8
9fdee384c3022847ac62488c4643803bdd66395b
2014-01-10T13:48:43Z
new file mode 100644 <nl> index 000000000000 . . cf08ba71d166 <nl> mmm / dev / null <nl> ppp b / jstests / noPassthrough / index_stepdown_failover . js <nl> <nl> + / * * <nl> + * Confirms that index builds on a stepped down primary are not aborted and will <nl> + * wait for a commitIndexBuild from the new primary before committing . <nl> + * @ tags : [ <nl> + * requires_replication , <nl> + * ] <nl> + * / <nl> + ( function ( ) { <nl> + " use strict " ; <nl> + <nl> + load ( ' jstests / libs / check_log . js ' ) ; <nl> + load ( ' jstests / noPassthrough / libs / index_build . js ' ) ; <nl> + <nl> + const rst = new ReplSetTest ( { <nl> + / / We want at least two electable nodes . <nl> + nodes : [ { } , { } , { arbiter : true } ] , <nl> + } ) ; <nl> + const nodes = rst . startSet ( ) ; <nl> + rst . initiate ( ) ; <nl> + <nl> + const primary = rst . getPrimary ( ) ; <nl> + const testDB = primary . getDB ( ' test ' ) ; <nl> + const coll = testDB . getCollection ( ' test ' ) ; <nl> + <nl> + const enableTwoPhaseIndexBuild = <nl> + assert . commandWorked ( primary . adminCommand ( { getParameter : 1 , enableTwoPhaseIndexBuild : 1 } ) ) <nl> + . enableTwoPhaseIndexBuild ; <nl> + if ( ! enableTwoPhaseIndexBuild ) { <nl> + jsTestLog ( ' Two phase index builds not enabled , skipping test . ' ) ; <nl> + rst . stopSet ( ) ; <nl> + return ; <nl> + } <nl> + <nl> + assert . commandWorked ( coll . insert ( { a : 1 } ) ) ; <nl> + <nl> + / / Start index build on primary , but prevent it from finishing . <nl> + IndexBuildTest . pauseIndexBuilds ( primary ) ; <nl> + const createIdx = IndexBuildTest . startIndexBuild ( primary , coll . getFullName ( ) , { a : 1 } ) ; <nl> + <nl> + / / Wait for the index build to start on the secondary . <nl> + const secondary = rst . getSecondary ( ) ; <nl> + const secondaryDB = secondary . getDB ( testDB . getName ( ) ) ; <nl> + const secondaryColl = secondaryDB . getCollection ( coll . getName ( ) ) ; <nl> + IndexBuildTest . waitForIndexBuildToStart ( secondaryDB ) ; <nl> + IndexBuildTest . assertIndexes ( secondaryColl , 2 , [ " _id_ " ] , [ " a_1 " ] , { includeBuildUUIDs : true } ) ; <nl> + <nl> + const newPrimary = rst . getSecondary ( ) ; <nl> + const newPrimaryDB = secondaryDB ; <nl> + const newPrimaryColl = secondaryColl ; <nl> + <nl> + / / Step down the primary . <nl> + / / Expect failed createIndex command invocation in parallel shell due to stepdown . <nl> + / / Before SERVER - 44186 , the index build will be aborted during stepdown . <nl> + assert . commandWorked ( primary . adminCommand ( { replSetStepDown : 60 , force : true } ) ) ; <nl> + const exitCode = createIdx ( { checkExitSuccess : false } ) ; <nl> + assert . neq ( 0 , exitCode , ' expected shell to exit abnormally due to index build being terminated ' ) ; <nl> + checkLog . contains ( primary , ' Index build interrupted : ' ) ; <nl> + <nl> + / / Unblock the index build on the old primary during the collection scanning phase . <nl> + IndexBuildTest . resumeIndexBuilds ( primary ) ; <nl> + <nl> + / / Step up the new primary . <nl> + rst . stepUp ( newPrimary ) ; <nl> + <nl> + / / A new index should not be present on the old primary because the index build was aborted . <nl> + IndexBuildTest . waitForIndexBuildToStop ( testDB ) ; <nl> + IndexBuildTest . assertIndexes ( coll , 1 , [ ' _id_ ' ] ) ; <nl> + <nl> + TestData . skipCheckDBHashes = true ; <nl> + rst . stopSet ( ) ; <nl> + } ) ( ) ; <nl>
SERVER - 44186 add js test for testing index build failover
mongodb/mongo
cbe0aee62546b9672baf66133a682da5fa3e58a5
2019-10-27T21:23:42Z
mmm a / src / core / lib / iomgr / ev_epollex_linux . cc <nl> ppp b / src / core / lib / iomgr / ev_epollex_linux . cc <nl> <nl> / / # define GRPC_EPOLLEX_CREATE_WORKERS_ON_HEAP 1 <nl> <nl> # define MAX_EPOLL_EVENTS 100 <nl> - # define MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL 16 <nl> + # define MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL 1 <nl> <nl> grpc_core : : DebugOnlyTraceFlag grpc_trace_pollable_refcount ( false , <nl> " pollable_refcount " ) ; <nl> struct grpc_pollset_worker { <nl> <nl> struct grpc_pollset { <nl> gpr_mu mu ; <nl> - gpr_atm worker_count ; <nl> pollable * active_pollable ; <nl> bool kicked_without_poller ; <nl> grpc_closure * shutdown_closure ; <nl> static grpc_error * pollset_kick_all ( grpc_pollset * pollset ) { <nl> <nl> static void pollset_init ( grpc_pollset * pollset , gpr_mu * * mu ) { <nl> gpr_mu_init ( & pollset - > mu ) ; <nl> - gpr_atm_no_barrier_store ( & pollset - > worker_count , 0 ) ; <nl> pollset - > active_pollable = POLLABLE_REF ( g_empty_pollable , " pollset " ) ; <nl> pollset - > kicked_without_poller = false ; <nl> pollset - > shutdown_closure = nullptr ; <nl> static grpc_error * pollable_process_events ( grpc_pollset * pollset , <nl> pollable * pollable_obj , bool drain ) { <nl> GPR_TIMER_SCOPE ( " pollable_process_events " , 0 ) ; <nl> static const char * err_desc = " pollset_process_events " ; <nl> - / / Use a simple heuristic to determine how many fd events to process <nl> - / / per loop iteration . ( events / workers ) <nl> - int handle_count = 1 ; <nl> - int worker_count = gpr_atm_no_barrier_load ( & pollset - > worker_count ) ; <nl> - GPR_ASSERT ( worker_count > 0 ) ; <nl> - handle_count = <nl> - ( pollable_obj - > event_count - pollable_obj - > event_cursor ) / worker_count ; <nl> - if ( handle_count = = 0 ) { <nl> - handle_count = 1 ; <nl> - } else if ( handle_count > MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL ) { <nl> - handle_count = MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL ; <nl> - } <nl> grpc_error * error = GRPC_ERROR_NONE ; <nl> - for ( int i = 0 ; ( drain | | i < handle_count ) & & <nl> + for ( int i = 0 ; ( drain | | i < MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL ) & & <nl> pollable_obj - > event_cursor ! = pollable_obj - > event_count ; <nl> i + + ) { <nl> int n = pollable_obj - > event_cursor + + ; <nl> static bool begin_worker ( grpc_pollset * pollset , grpc_pollset_worker * worker , <nl> GPR_TIMER_SCOPE ( " begin_worker " , 0 ) ; <nl> bool do_poll = <nl> ( pollset - > shutdown_closure = = nullptr & & ! pollset - > already_shutdown ) ; <nl> - gpr_atm_no_barrier_fetch_add ( & pollset - > worker_count , 1 ) ; <nl> if ( worker_hdl ! = nullptr ) * worker_hdl = worker ; <nl> worker - > initialized_cv = false ; <nl> worker - > kicked = false ; <nl> static void end_worker ( grpc_pollset * pollset , grpc_pollset_worker * worker , <nl> if ( worker - > initialized_cv ) { <nl> gpr_cv_destroy ( & worker - > cv ) ; <nl> } <nl> - gpr_atm_no_barrier_fetch_add ( & pollset - > worker_count , - 1 ) ; <nl> } <nl> <nl> # ifndef NDEBUG <nl>
Revert " Use heuristic to determine how many events to handle per iteration "
grpc/grpc
fb0dabd17075fef5f46db03b991b5552921881d7
2018-03-13T16:58:57Z
mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioAssets . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioAssets . cpp <nl> <nl> <nl> # include " StdAfx . h " <nl> # include " AudioAssets . h " <nl> + <nl> # include " AudioAssetsManager . h " <nl> - # include " IEditor . h " <nl> - # include < IAudioSystemItem . h > <nl> - # include < ACETypes . h > <nl> # include " AudioControlsEditorPlugin . h " <nl> # include " ImplementationManager . h " <nl> + <nl> + # include < IEditor . h > <nl> + # include < IAudioSystemItem . h > <nl> # include < CrySerialization / StringList . h > <nl> # include < CrySerialization / Decorators / Range . h > <nl> # include < Serialization / Decorators / EditorActionButton . h > <nl> void CAudioAsset : : RemoveChild ( CAudioAsset * pChildControl ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CAudioControl : : CAudioControl ( const string & controlName , CID id , EItemType type ) <nl> + void CAudioAsset : : SetModified ( bool const bModified , bool const bForce / * = false * / ) <nl> + { <nl> + if ( m_pParent ! = nullptr & & ( ! CAudioControlsEditorPlugin : : GetAssetsManager ( ) - > IsLoading ( ) | | bForce ) ) <nl> + { <nl> + CAudioControlsEditorPlugin : : GetAssetsManager ( ) - > SetAssetModified ( this ) ; <nl> + m_bModified = bModified ; <nl> + / / Note : This need to get changed once undo is working . <nl> + / / Then we can ' t set the parent to be not modified if it still could contain other modified children . <nl> + m_pParent - > SetModified ( bModified , bForce ) ; <nl> + } <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + CAudioControl : : CAudioControl ( string const & controlName , CID const id , EItemType const type ) <nl> : CAudioAsset ( controlName ) <nl> , m_id ( id ) <nl> , m_type ( type ) <nl> CAudioControl : : ~ CAudioControl ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CID CAudioControl : : GetId ( ) const <nl> - { <nl> - return m_id ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControl : : SetName ( const string & name ) <nl> + void CAudioControl : : SetName ( string const & name ) <nl> { <nl> if ( name ! = m_name ) <nl> { <nl> void CAudioControl : : SetName ( const string & name ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - Scope CAudioControl : : GetScope ( ) const <nl> - { <nl> - return m_scope ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControl : : SetScope ( Scope scope ) <nl> + void CAudioControl : : SetScope ( Scope const scope ) <nl> { <nl> if ( m_scope ! = scope ) <nl> { <nl> void CAudioControl : : SetScope ( Scope scope ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - bool CAudioControl : : IsAutoLoad ( ) const <nl> - { <nl> - return m_bAutoLoad ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControl : : SetAutoLoad ( bool bAutoLoad ) <nl> + void CAudioControl : : SetAutoLoad ( bool const bAutoLoad ) <nl> { <nl> if ( bAutoLoad ! = m_bAutoLoad ) <nl> { <nl> void CAudioControl : : SetAutoLoad ( bool bAutoLoad ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - size_t CAudioControl : : GetConnectionCount ( ) <nl> - { <nl> - return m_connectedControls . size ( ) ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - ConnectionPtr CAudioControl : : GetConnectionAt ( int index ) <nl> + ConnectionPtr CAudioControl : : GetConnectionAt ( int const index ) const <nl> { <nl> if ( index < m_connectedControls . size ( ) ) <nl> { <nl> ConnectionPtr CAudioControl : : GetConnectionAt ( int index ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - ConnectionPtr CAudioControl : : GetConnection ( CID id ) <nl> + ConnectionPtr CAudioControl : : GetConnection ( CID const id ) const <nl> { <nl> for ( auto const pConnection : m_connectedControls ) <nl> { <nl> - if ( pConnection ! = nullptr & & pConnection - > GetID ( ) = = id ) <nl> + if ( ( pConnection ! = nullptr ) & & ( pConnection - > GetID ( ) = = id ) ) <nl> { <nl> return pConnection ; <nl> } <nl> ConnectionPtr CAudioControl : : GetConnection ( CID id ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - ConnectionPtr CAudioControl : : GetConnection ( IAudioSystemItem * pAudioSystemControl ) <nl> + ConnectionPtr CAudioControl : : GetConnection ( IAudioSystemItem * pAudioSystemControl ) const <nl> { <nl> return GetConnection ( pAudioSystemControl - > GetId ( ) ) ; <nl> } <nl> void CAudioControl : : RemoveConnection ( ConnectionPtr pConnection ) <nl> { <nl> if ( pConnection ) <nl> { <nl> - auto it = std : : find ( m_connectedControls . begin ( ) , m_connectedControls . end ( ) , pConnection ) ; <nl> + auto const it = std : : find ( m_connectedControls . begin ( ) , m_connectedControls . end ( ) , pConnection ) ; <nl> <nl> if ( it ! = m_connectedControls . end ( ) ) <nl> { <nl> void CAudioControl : : RemoveConnection ( IAudioSystemItem * pAudioSystemControl ) <nl> { <nl> if ( pAudioSystemControl ) <nl> { <nl> - const CID id = pAudioSystemControl - > GetId ( ) ; <nl> + CID const id = pAudioSystemControl - > GetId ( ) ; <nl> auto it = m_connectedControls . begin ( ) ; <nl> - auto end = m_connectedControls . end ( ) ; <nl> + auto const end = m_connectedControls . end ( ) ; <nl> <nl> for ( ; it ! = end ; + + it ) <nl> { <nl> void CAudioControl : : ReloadConnections ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControl : : LoadConnectionFromXML ( XmlNodeRef xmlNode , int platformIndex ) <nl> + void CAudioControl : : LoadConnectionFromXML ( XmlNodeRef xmlNode , int const platformIndex ) <nl> { <nl> IAudioSystemEditor * pAudioSystemImpl = CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > GetImplementation ( ) ; <nl> <nl> void CAudioControl : : LoadConnectionFromXML ( XmlNodeRef xmlNode , int platformIndex ) <nl> <nl> if ( pConnection ) <nl> { <nl> - if ( GetType ( ) = = eItemType_Preload ) <nl> + if ( GetType ( ) = = EItemType : : Preload ) <nl> { <nl> / / The connection could already exist but using a different platform <nl> ConnectionPtr pPreviousConnection = GetConnection ( pConnection - > GetID ( ) ) ; <nl> void CAudioControl : : LoadConnectionFromXML ( XmlNodeRef xmlNode , int platformIndex ) <nl> AddConnection ( pConnection ) ; <nl> } <nl> } <nl> - else if ( GetType ( ) = = eItemType_Preload & & platformIndex = = - 1 ) <nl> + else if ( ( GetType ( ) = = EItemType : : Preload ) & & ( platformIndex = = - 1 ) ) <nl> { <nl> / / If it ' s a preload connection from another middleware and the platform <nl> / / wasn ' t found ( old file format ) fall back to adding them to all the platforms <nl> - const std : : vector < dll_string > & platforms = GetIEditor ( ) - > GetConfigurationManager ( ) - > GetPlatformNames ( ) ; <nl> - const size_t count = platforms . size ( ) ; <nl> + std : : vector < dll_string > const & platforms = GetIEditor ( ) - > GetConfigurationManager ( ) - > GetPlatformNames ( ) ; <nl> + size_t const count = platforms . size ( ) ; <nl> <nl> for ( size_t i = 0 ; i < count ; + + i ) <nl> { <nl> void CAudioControl : : Serialize ( Serialization : : IArchive & ar ) <nl> if ( ar . openBlock ( " properties " , " + Properties " ) ) <nl> { <nl> / / Name <nl> - string newName = m_name ; <nl> + string const newName = m_name ; <nl> ar ( newName , " name " , " Name " ) ; <nl> <nl> / / Scope <nl> void CAudioControl : : Serialize ( Serialization : : IArchive & ar ) <nl> scopeList . push_back ( scope . name ) ; <nl> } <nl> <nl> - Serialization : : StringListValue selectedScope ( scopeList , CAudioControlsEditorPlugin : : GetAssetsManager ( ) - > GetScopeInfo ( m_scope ) . name ) ; <nl> + Serialization : : StringListValue const selectedScope ( scopeList , CAudioControlsEditorPlugin : : GetAssetsManager ( ) - > GetScopeInfo ( m_scope ) . name ) ; <nl> Scope newScope = m_scope ; <nl> <nl> - if ( m_type ! = eItemType_State ) <nl> + if ( m_type ! = EItemType : : State ) <nl> { <nl> ar ( selectedScope , " scope " , " Scope " ) ; <nl> newScope = CAudioControlsEditorPlugin : : GetAssetsManager ( ) - > GetScope ( scopeList [ selectedScope . index ( ) ] ) ; <nl> void CAudioControl : : Serialize ( Serialization : : IArchive & ar ) <nl> / / Auto Load <nl> bool bAutoLoad = m_bAutoLoad ; <nl> <nl> - if ( m_type = = eItemType_Preload ) <nl> + if ( m_type = = EItemType : : Preload ) <nl> { <nl> ar ( bAutoLoad , " auto_load " , " Auto Load " ) ; <nl> } <nl> void CAudioControl : : Serialize ( Serialization : : IArchive & ar ) <nl> float radius = m_radius ; <nl> float fadeOutDistance = m_occlusionFadeOutDistance ; <nl> <nl> - if ( m_type = = eItemType_Trigger & & ar . openBlock ( " activity_radius " , " Activity Radius " ) ) <nl> + if ( ( m_type = = EItemType : : Trigger ) & & ( ar . openBlock ( " activity_radius " , " Activity Radius " ) ) ) <nl> { <nl> bool hasPlaceholderConnections = false ; <nl> IAudioSystemEditor const * const pAudioSystemImpl = CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > GetImplementation ( ) ; <nl> void CAudioControl : : Serialize ( Serialization : : IArchive & ar ) <nl> { <nl> IAudioSystemItem const * const pItem = pAudioSystemImpl - > GetControl ( pConnection - > GetID ( ) ) ; <nl> <nl> - if ( pItem ! = nullptr & & ! pItem - > IsPlaceholder ( ) ) <nl> + if ( ( pItem ! = nullptr ) & & ( ! pItem - > IsPlaceholder ( ) ) ) <nl> { <nl> radius = std : : max ( radius , pItem - > GetRadius ( ) ) ; <nl> } <nl> void CAudioControl : : Serialize ( Serialization : : IArchive & ar ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - bool CAudioControl : : IsModified ( ) const <nl> - { <nl> - if ( m_pParent ) <nl> - { <nl> - return m_pParent - > IsModified ( ) ; <nl> - } <nl> - <nl> - return false ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControl : : SetModified ( bool const bModified , bool const bForce / * = false * / ) <nl> - { <nl> - if ( m_pParent ! = nullptr & & ( ! CAudioControlsEditorPlugin : : GetAssetsManager ( ) - > IsLoading ( ) | | bForce ) ) <nl> - { <nl> - CAudioControlsEditorPlugin : : GetAssetsManager ( ) - > SetAssetModified ( this ) ; <nl> - m_pParent - > SetModified ( bModified , bForce ) ; <nl> - } <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControl : : SetOcclusionFadeOutDistance ( float fadeOutDistance ) <nl> + void CAudioControl : : SetOcclusionFadeOutDistance ( float const fadeOutDistance ) <nl> { <nl> if ( fadeOutDistance ! = m_occlusionFadeOutDistance ) <nl> { <nl> void CAudioControl : : SetOcclusionFadeOutDistance ( float fadeOutDistance ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControl : : AddRawXMLConnection ( XmlNodeRef xmlNode , bool bValid , int platformIndex / * = - 1 * / ) <nl> + void CAudioControl : : AddRawXMLConnection ( XmlNodeRef xmlNode , bool const bValid , int const platformIndex / * = - 1 * / ) <nl> { <nl> m_connectionNodes [ platformIndex ] . emplace_back ( xmlNode , bValid ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - XMLNodeList & CAudioControl : : GetRawXMLConnections ( int platformIndex / * = - 1 * / ) <nl> + XMLNodeList & CAudioControl : : GetRawXMLConnections ( int const platformIndex / * = - 1 * / ) <nl> { <nl> return m_connectionNodes [ platformIndex ] ; <nl> } <nl> void CAudioControl : : MatchRadiusToAttenuation ( ) <nl> } <nl> } <nl> <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - bool CAudioFolder : : IsModified ( ) const <nl> - { <nl> - if ( m_pParent ) <nl> - { <nl> - return m_pParent - > IsModified ( ) ; <nl> - } <nl> - <nl> - return false ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioFolder : : SetModified ( bool const bModified , bool const bForce / * = false * / ) <nl> - { <nl> - if ( m_pParent ! = nullptr & & ( ! CAudioControlsEditorPlugin : : GetAssetsManager ( ) - > IsLoading ( ) | | bForce ) ) <nl> - { <nl> - CAudioControlsEditorPlugin : : GetAssetsManager ( ) - > SetAssetModified ( this ) ; <nl> - m_pParent - > SetModified ( bModified , bForce ) ; <nl> - } <nl> - } <nl> - <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioLibrary : : SetModified ( bool const bModified , bool const bForce / * = false * / ) <nl> { <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioAssets . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioAssets . h <nl> class IAudioSystemItem ; <nl> <nl> struct SRawConnectionData <nl> { <nl> - SRawConnectionData ( XmlNodeRef node , bool bIsValid ) <nl> + SRawConnectionData ( XmlNodeRef node , bool const bIsValid ) <nl> : xmlNode ( node ) <nl> , bValid ( bIsValid ) { } <nl> <nl> class CAudioAsset <nl> { <nl> public : <nl> <nl> - CAudioAsset ( const string & name ) : m_name ( name ) { } <nl> - virtual EItemType GetType ( ) const { return eItemType_Invalid ; } <nl> + CAudioAsset ( string const & name ) : m_name ( name ) { } <nl> + <nl> + virtual EItemType GetType ( ) const { return EItemType : : Invalid ; } <nl> <nl> CAudioAsset * GetParent ( ) const { return m_pParent ; } <nl> void SetParent ( CAudioAsset * pParent ) ; <nl> class CAudioAsset <nl> void RemoveChild ( CAudioAsset * pChildControl ) ; <nl> <nl> string GetName ( ) const { return m_name ; } <nl> - virtual void SetName ( const string & name ) { m_name = name ; } <nl> + virtual void SetName ( string const & name ) { m_name = name ; } <nl> <nl> - virtual bool IsModified ( ) const = 0 ; <nl> - virtual void SetModified ( bool const bModified , bool const bForce = false ) = 0 ; <nl> + virtual bool IsModified ( ) const { return m_bModified ; } <nl> + virtual void SetModified ( bool const bModified , bool const bForce = false ) ; <nl> <nl> - void SetHasPlaceholderConnection ( bool const bHasPlaceholder ) { m_bHasPlaceholderConnection = bHasPlaceholder ; } <nl> bool HasPlaceholderConnection ( ) const { return m_bHasPlaceholderConnection ; } <nl> - <nl> - void SetHasConnection ( bool const bHasConnection ) { m_bHasConnection = bHasConnection ; } <nl> + void SetHasPlaceholderConnection ( bool const bHasPlaceholder ) { m_bHasPlaceholderConnection = bHasPlaceholder ; } <nl> + <nl> bool HasConnection ( ) const { return m_bHasConnection ; } <nl> - <nl> - void SetHasControl ( bool const bHasControl ) { m_bHasControl = bHasControl ; } <nl> + void SetHasConnection ( bool const bHasConnection ) { m_bHasConnection = bHasConnection ; } <nl> + <nl> bool HasControl ( ) const { return m_bHasControl ; } <nl> + void SetHasControl ( bool const bHasControl ) { m_bHasControl = bHasControl ; } <nl> <nl> protected : <nl> <nl> CAudioAsset * m_pParent = nullptr ; <nl> std : : vector < CAudioAsset * > m_children ; <nl> string m_name ; <nl> + bool m_bModified = false ; <nl> bool m_bHasPlaceholderConnection = false ; <nl> bool m_bHasConnection = false ; <nl> bool m_bHasControl = false ; <nl> } ; <nl> <nl> - class CAudioLibrary : public CAudioAsset <nl> - { <nl> - public : <nl> - <nl> - CAudioLibrary ( const string & name ) : CAudioAsset ( name ) { } <nl> - virtual EItemType GetType ( ) const override { return eItemType_Library ; } <nl> - bool IsModified ( ) const override { return m_bModified ; } <nl> - virtual void SetModified ( bool const bModified , bool const bForce = false ) override ; <nl> - <nl> - private : <nl> - <nl> - bool m_bModified = false ; <nl> - } ; <nl> - <nl> - class CAudioFolder : public CAudioAsset <nl> - { <nl> - public : <nl> - <nl> - CAudioFolder ( const string & name ) : CAudioAsset ( name ) { } <nl> - virtual EItemType GetType ( ) const override { return eItemType_Folder ; } <nl> - bool IsModified ( ) const override ; <nl> - virtual void SetModified ( bool const bModified , bool const bForce = false ) override ; <nl> - } ; <nl> - <nl> - class CAudioControl : public CAudioAsset <nl> + class CAudioControl final : public CAudioAsset <nl> { <nl> friend class CAudioControlsLoader ; <nl> friend class CAudioControlsWriter ; <nl> class CAudioControl : public CAudioAsset <nl> public : <nl> <nl> CAudioControl ( ) = default ; <nl> - CAudioControl ( const string & controlName , CID id , EItemType type ) ; <nl> + CAudioControl ( string const & controlName , CID const id , EItemType const type ) ; <nl> ~ CAudioControl ( ) ; <nl> <nl> - CID GetId ( ) const ; <nl> + CID GetId ( ) const { return m_id ; } <nl> EItemType GetType ( ) const override { return m_type ; } <nl> <nl> - virtual void SetName ( const string & name ) override ; <nl> + virtual void SetName ( string const & name ) override ; <nl> <nl> - Scope GetScope ( ) const ; <nl> - void SetScope ( Scope scope ) ; <nl> + Scope GetScope ( ) const { return m_scope ; } <nl> + void SetScope ( Scope const scope ) ; <nl> <nl> - bool IsAutoLoad ( ) const ; <nl> - void SetAutoLoad ( bool bAutoLoad ) ; <nl> + bool IsAutoLoad ( ) const { return m_bAutoLoad ; } <nl> + void SetAutoLoad ( bool const bAutoLoad ) ; <nl> <nl> float GetRadius ( ) const { return m_radius ; } <nl> void SetRadius ( float const radius ) { m_radius = radius ; } <nl> <nl> float GetOcclusionFadeOutDistance ( ) const { return m_occlusionFadeOutDistance ; } <nl> - void SetOcclusionFadeOutDistance ( float fadeOutArea ) ; <nl> + void SetOcclusionFadeOutDistance ( float const fadeOutArea ) ; <nl> <nl> - size_t GetConnectionCount ( ) ; <nl> + size_t GetConnectionCount ( ) const { return m_connectedControls . size ( ) ; } <nl> void AddConnection ( ConnectionPtr pConnection ) ; <nl> void RemoveConnection ( ConnectionPtr pConnection ) ; <nl> void RemoveConnection ( IAudioSystemItem * pAudioSystemControl ) ; <nl> void ClearConnections ( ) ; <nl> - ConnectionPtr GetConnectionAt ( int index ) ; <nl> - ConnectionPtr GetConnection ( CID id ) ; <nl> - ConnectionPtr GetConnection ( IAudioSystemItem * pAudioSystemControl ) ; <nl> + ConnectionPtr GetConnectionAt ( int const index ) const ; <nl> + ConnectionPtr GetConnection ( CID const id ) const ; <nl> + ConnectionPtr GetConnection ( IAudioSystemItem * pAudioSystemControl ) const ; <nl> void ReloadConnections ( ) ; <nl> - void LoadConnectionFromXML ( XmlNodeRef xmlNode , int platformIndex = - 1 ) ; <nl> + void LoadConnectionFromXML ( XmlNodeRef xmlNode , int const platformIndex = - 1 ) ; <nl> <nl> void MatchRadiusToAttenuation ( ) ; <nl> bool IsMatchRadiusToAttenuationEnabled ( ) const { return m_bMatchRadiusAndAttenuation ; } <nl> - void SetMatchRadiusToAttenuationEnabled ( bool bEnabled ) { m_bMatchRadiusAndAttenuation = bEnabled ; } <nl> + void SetMatchRadiusToAttenuationEnabled ( bool const bEnabled ) { m_bMatchRadiusAndAttenuation = bEnabled ; } <nl> <nl> void Serialize ( Serialization : : IArchive & ar ) ; <nl> <nl> - virtual bool IsModified ( ) const override ; <nl> - virtual void SetModified ( bool const bModified , bool const bForce = false ) override ; <nl> - <nl> private : <nl> <nl> void SignalControlAboutToBeModified ( ) ; <nl> class CAudioControl : public CAudioAsset <nl> void SignalConnectionModified ( ) ; <nl> <nl> CID m_id = ACE_INVALID_ID ; <nl> - EItemType m_type = eItemType_Trigger ; <nl> + EItemType m_type = EItemType : : Trigger ; <nl> Scope m_scope = 0 ; <nl> std : : vector < ConnectionPtr > m_connectedControls ; <nl> float m_radius = 0 . 0f ; <nl> class CAudioControl : public CAudioAsset <nl> bool m_bMatchRadiusAndAttenuation = true ; <nl> <nl> / / All the raw connection nodes . Used for reloading the data when switching middleware . <nl> - void AddRawXMLConnection ( XmlNodeRef xmlNode , bool bValid , int platformIndex = - 1 ) ; <nl> - XMLNodeList & GetRawXMLConnections ( int platformIndex = - 1 ) ; <nl> + void AddRawXMLConnection ( XmlNodeRef xmlNode , bool const bValid , int const platformIndex = - 1 ) ; <nl> + XMLNodeList & GetRawXMLConnections ( int const platformIndex = - 1 ) ; <nl> std : : map < int , XMLNodeList > m_connectionNodes ; <nl> <nl> bool m_modifiedSignalEnabled = true ; <nl> } ; <nl> + <nl> + class CAudioLibrary final : public CAudioAsset <nl> + { <nl> + public : <nl> + <nl> + CAudioLibrary ( string const & name ) : CAudioAsset ( name ) { } <nl> + <nl> + virtual EItemType GetType ( ) const override { return EItemType : : Library ; } <nl> + virtual void SetModified ( bool const bModified , bool const bForce = false ) override ; <nl> + } ; <nl> + <nl> + class CAudioFolder final : public CAudioAsset <nl> + { <nl> + public : <nl> + <nl> + CAudioFolder ( string const & name ) : CAudioAsset ( name ) { } <nl> + <nl> + virtual EItemType GetType ( ) const override { return EItemType : : Folder ; } <nl> + } ; <nl> } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioAssetsManager . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioAssetsManager . cpp <nl> <nl> <nl> # include " StdAfx . h " <nl> # include " AudioAssetsManager . h " <nl> - # include < CryString / StringUtils . h > <nl> + <nl> # include " AudioControlsEditorUndo . h " <nl> # include " AudioControlsEditorPlugin . h " <nl> # include " ImplementationManager . h " <nl> # include " IAudioSystemEditor . h " <nl> # include " IAudioSystemItem . h " <nl> - # include < IEditor . h > <nl> + <nl> + # include < CryString / StringUtils . h > <nl> # include < CryString / CryPath . h > <nl> # include < FilePathUtil . h > <nl> + # include < IEditor . h > <nl> <nl> namespace ACE <nl> { <nl> uint ItemTypeToIndex ( EItemType const type ) <nl> { <nl> switch ( type ) <nl> { <nl> - case EItemType : : eItemType_Trigger : <nl> + case EItemType : : Trigger : <nl> return 0 ; <nl> - case EItemType : : eItemType_Parameter : <nl> + case EItemType : : Parameter : <nl> return 1 ; <nl> - case EItemType : : eItemType_Switch : <nl> + case EItemType : : Switch : <nl> return 2 ; <nl> - case EItemType : : eItemType_State : <nl> + case EItemType : : State : <nl> return 3 ; <nl> - case EItemType : : eItemType_Environment : <nl> + case EItemType : : Environment : <nl> return 4 ; <nl> - case EItemType : : eItemType_Preload : <nl> + case EItemType : : Preload : <nl> return 5 ; <nl> - case EItemType : : eItemType_Folder : <nl> + case EItemType : : Folder : <nl> return 6 ; <nl> - case EItemType : : eItemType_Library : <nl> + case EItemType : : Library : <nl> return 7 ; <nl> } <nl> <nl> void CAudioAssetsManager : : Initialize ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CAudioControl * CAudioAssetsManager : : CreateControl ( string const & name , EItemType type , CAudioAsset * pParent ) <nl> + CAudioControl * CAudioAssetsManager : : CreateControl ( string const & name , EItemType const type , CAudioAsset * const pParent ) <nl> { <nl> if ( pParent ! = nullptr & & ! name . empty ( ) ) <nl> { <nl> - if ( ( pParent - > GetType ( ) = = EItemType : : eItemType_Folder | | pParent - > GetType ( ) = = EItemType : : eItemType_Library ) | | <nl> - ( pParent - > GetType ( ) = = EItemType : : eItemType_Switch & & type = = EItemType : : eItemType_State ) ) <nl> + if ( ( pParent - > GetType ( ) = = EItemType : : Folder | | pParent - > GetType ( ) = = EItemType : : Library ) | | <nl> + ( pParent - > GetType ( ) = = EItemType : : Switch & & type = = EItemType : : State ) ) <nl> { <nl> CAudioControl * const pFoundControl = FindControl ( name , type , pParent ) ; <nl> <nl> CAudioControl * CAudioAssetsManager : : CreateControl ( string const & name , EItemType <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioAssetsManager : : DeleteItem ( CAudioAsset * pItem ) <nl> + void CAudioAssetsManager : : DeleteItem ( CAudioAsset * const pItem ) <nl> { <nl> if ( pItem ) <nl> { <nl> void CAudioAssetsManager : : DeleteItem ( CAudioAsset * pItem ) <nl> EItemType const type = pItem - > GetType ( ) ; <nl> <nl> / / Inform that we ' re about to remove the item <nl> - if ( type = = EItemType : : eItemType_Library ) <nl> + if ( type = = EItemType : : Library ) <nl> { <nl> signalLibraryAboutToBeRemoved ( static_cast < CAudioLibrary * > ( pItem ) ) ; <nl> } <nl> void CAudioAssetsManager : : DeleteItem ( CAudioAsset * pItem ) <nl> } <nl> <nl> / / Remove / detach item from the tree <nl> - CAudioAsset * pParent = pItem - > GetParent ( ) ; <nl> + CAudioAsset * const pParent = pItem - > GetParent ( ) ; <nl> <nl> if ( pParent ) <nl> { <nl> void CAudioAssetsManager : : DeleteItem ( CAudioAsset * pItem ) <nl> pItem - > SetParent ( nullptr ) ; <nl> } <nl> <nl> - if ( type = = EItemType : : eItemType_Library ) <nl> + if ( type = = EItemType : : Library ) <nl> { <nl> m_audioLibraries . erase ( std : : remove ( m_audioLibraries . begin ( ) , m_audioLibraries . end ( ) , static_cast < CAudioLibrary * > ( pItem ) ) , m_audioLibraries . end ( ) ) ; <nl> signalLibraryRemoved ( ) ; <nl> } <nl> else <nl> { <nl> - if ( type ! = EItemType : : eItemType_Folder ) <nl> + if ( type ! = EItemType : : Folder ) <nl> { <nl> / / Must be a control <nl> - CAudioControl * pControl = static_cast < CAudioControl * > ( pItem ) ; <nl> + CAudioControl * const pControl = static_cast < CAudioControl * > ( pItem ) ; <nl> <nl> if ( pControl ) <nl> { <nl> void CAudioAssetsManager : : DeleteItem ( CAudioAsset * pItem ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CAudioControl * CAudioAssetsManager : : GetControlByID ( CID id ) const <nl> + CAudioControl * CAudioAssetsManager : : GetControlByID ( CID const id ) const <nl> { <nl> for ( auto const pControl : m_controls ) <nl> { <nl> void CAudioAssetsManager : : ClearScopes ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioAssetsManager : : AddScope ( string const & name , bool bLocalOnly ) <nl> + void CAudioAssetsManager : : AddScope ( string const & name , bool const bLocalOnly ) <nl> { <nl> string scopeName = name ; <nl> m_scopeMap [ CCrc32 : : Compute ( scopeName . MakeLower ( ) ) ] = SScopeInfo ( scopeName , bLocalOnly ) ; <nl> Scope CAudioAssetsManager : : GetScope ( string const & name ) const <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - SScopeInfo CAudioAssetsManager : : GetScopeInfo ( Scope id ) const <nl> + SScopeInfo CAudioAssetsManager : : GetScopeInfo ( Scope const id ) const <nl> { <nl> return stl : : find_in_map ( m_scopeMap , id , SScopeInfo ( ) ) ; <nl> } <nl> SScopeInfo CAudioAssetsManager : : GetScopeInfo ( Scope id ) const <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioAssetsManager : : Clear ( ) <nl> { <nl> - std : : vector < CAudioLibrary * > libraries = m_audioLibraries ; <nl> + std : : vector < CAudioLibrary * > const libraries = m_audioLibraries ; <nl> <nl> - for ( auto pLibrary : libraries ) <nl> + for ( auto const pLibrary : libraries ) <nl> { <nl> DeleteItem ( pLibrary ) ; <nl> } <nl> CAudioLibrary * CAudioAssetsManager : : CreateLibrary ( string const & name ) <nl> <nl> for ( size_t i = 0 ; i < size ; + + i ) <nl> { <nl> - CAudioLibrary * pLibrary = m_audioLibraries [ i ] ; <nl> + CAudioLibrary * const pLibrary = m_audioLibraries [ i ] ; <nl> <nl> if ( pLibrary & & ( name . compareNoCase ( pLibrary - > GetName ( ) ) = = 0 ) ) <nl> { <nl> CAudioLibrary * CAudioAssetsManager : : CreateLibrary ( string const & name ) <nl> } <nl> <nl> signalLibraryAboutToBeAdded ( ) ; <nl> - CAudioLibrary * pLibrary = new CAudioLibrary ( name ) ; <nl> + CAudioLibrary * const pLibrary = new CAudioLibrary ( name ) ; <nl> m_audioLibraries . push_back ( pLibrary ) ; <nl> signalLibraryAdded ( pLibrary ) ; <nl> pLibrary - > SetModified ( true ) ; <nl> CAudioLibrary * CAudioAssetsManager : : CreateLibrary ( string const & name ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - ACE : : CAudioAsset * CAudioAssetsManager : : CreateFolder ( string const & name , CAudioAsset * pParent ) <nl> + CAudioAsset * CAudioAssetsManager : : CreateFolder ( string const & name , CAudioAsset * const pParent ) <nl> { <nl> - if ( pParent ! = nullptr & & ! name . empty ( ) ) <nl> + if ( ( pParent ! = nullptr ) & & ! name . empty ( ) ) <nl> { <nl> - if ( pParent - > GetType ( ) = = EItemType : : eItemType_Folder | | pParent - > GetType ( ) = = EItemType : : eItemType_Library ) <nl> + if ( ( pParent - > GetType ( ) = = EItemType : : Folder ) | | ( pParent - > GetType ( ) = = EItemType : : Library ) ) <nl> { <nl> size_t const size = pParent - > ChildCount ( ) ; <nl> <nl> ACE : : CAudioAsset * CAudioAssetsManager : : CreateFolder ( string const & name , CAudioAs <nl> { <nl> CAudioAsset * const pItem = pParent - > GetChild ( i ) ; <nl> <nl> - if ( pItem ! = nullptr & & ( pItem - > GetType ( ) = = EItemType : : eItemType_Folder ) & & ( name . compareNoCase ( pItem - > GetName ( ) ) = = 0 ) ) <nl> + if ( ( pItem ! = nullptr ) & & ( pItem - > GetType ( ) = = EItemType : : Folder ) & & ( name . compareNoCase ( pItem - > GetName ( ) ) = = 0 ) ) <nl> { <nl> return pItem ; <nl> } <nl> ACE : : CAudioAsset * CAudioAssetsManager : : CreateFolder ( string const & name , CAudioAs <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioAssetsManager : : OnControlAboutToBeModified ( CAudioControl * pControl ) <nl> + void CAudioAssetsManager : : OnControlAboutToBeModified ( CAudioControl * const pControl ) <nl> { <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioAssetsManager : : OnConnectionAdded ( CAudioControl * pControl , IAudioSystemItem * pMiddlewareControl ) <nl> + void CAudioAssetsManager : : OnConnectionAdded ( CAudioControl * const pControl , IAudioSystemItem * const pMiddlewareControl ) <nl> { <nl> signalConnectionAdded ( pControl ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioAssetsManager : : OnConnectionRemoved ( CAudioControl * pControl , IAudioSystemItem * pMiddlewareControl ) <nl> + void CAudioAssetsManager : : OnConnectionRemoved ( CAudioControl * const pControl , IAudioSystemItem * const pMiddlewareControl ) <nl> { <nl> signalConnectionRemoved ( pControl ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioAssetsManager : : OnControlModified ( CAudioControl * pControl ) <nl> + void CAudioAssetsManager : : OnControlModified ( CAudioControl * const pControl ) <nl> { <nl> signalControlModified ( pControl ) ; <nl> m_bControlTypeModified [ ItemTypeToIndex ( pControl - > GetType ( ) ) ] = true ; <nl> void CAudioAssetsManager : : OnControlModified ( CAudioControl * pControl ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioAssetsManager : : SetAssetModified ( CAudioAsset * pAsset ) <nl> + void CAudioAssetsManager : : SetAssetModified ( CAudioAsset * const pAsset ) <nl> { <nl> UpdateLibraryConnectionStates ( pAsset ) ; <nl> m_bControlTypeModified [ ItemTypeToIndex ( pAsset - > GetType ( ) ) ] = true ; <nl> bool CAudioAssetsManager : : IsDirty ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - bool CAudioAssetsManager : : IsTypeDirty ( EItemType eType ) <nl> + bool CAudioAssetsManager : : IsTypeDirty ( EItemType const type ) <nl> { <nl> - return m_bControlTypeModified [ ItemTypeToIndex ( eType ) ] ; <nl> + return m_bControlTypeModified [ ItemTypeToIndex ( type ) ] ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CAudioControl * CAudioAssetsManager : : FindControl ( string const & controlName , EItem <nl> { <nl> for ( auto const pControl : m_controls ) <nl> { <nl> - if ( pControl ! = nullptr & & pControl - > GetName ( ) = = controlName & & pControl - > GetType ( ) = = type ) <nl> + if ( ( pControl ! = nullptr ) & & ( pControl - > GetName ( ) = = controlName ) & & ( pControl - > GetType ( ) = = type ) ) <nl> { <nl> return pControl ; <nl> } <nl> CAudioControl * CAudioAssetsManager : : FindControl ( string const & controlName , EItem <nl> { <nl> CAudioControl * const pControl = static_cast < CAudioControl * > ( pParent - > GetChild ( i ) ) ; <nl> <nl> - if ( pControl ! = nullptr & & pControl - > GetName ( ) = = controlName & & pControl - > GetType ( ) = = type ) <nl> + if ( ( pControl ! = nullptr ) & & ( pControl - > GetName ( ) = = controlName ) & & ( pControl - > GetType ( ) = = type ) ) <nl> { <nl> return pControl ; <nl> } <nl> void CAudioAssetsManager : : UpdateAllConnectionStates ( ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioAssetsManager : : UpdateLibraryConnectionStates ( CAudioAsset * pAsset ) <nl> { <nl> - while ( ( pAsset ! = nullptr ) & & ( pAsset - > GetType ( ) ! = EItemType : : eItemType_Library ) ) <nl> + while ( ( pAsset ! = nullptr ) & & ( pAsset - > GetType ( ) ! = EItemType : : Library ) ) <nl> { <nl> pAsset = pAsset - > GetParent ( ) ; <nl> } <nl> void CAudioAssetsManager : : UpdateLibraryConnectionStates ( CAudioAsset * pAsset ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioAssetsManager : : UpdateAssetConnectionStates ( CAudioAsset * pAsset ) <nl> + void CAudioAssetsManager : : UpdateAssetConnectionStates ( CAudioAsset * const pAsset ) <nl> { <nl> if ( pAsset ! = nullptr ) <nl> { <nl> - if ( ( pAsset - > GetType ( ) = = EItemType : : eItemType_Library ) | | ( pAsset - > GetType ( ) = = EItemType : : eItemType_Folder ) | | ( pAsset - > GetType ( ) = = EItemType : : eItemType_Switch ) ) <nl> + EItemType const type = pAsset - > GetType ( ) ; <nl> + <nl> + if ( ( type = = EItemType : : Library ) | | ( type = = EItemType : : Folder ) | | ( type = = EItemType : : Switch ) ) <nl> { <nl> bool bHasPlaceholder = false ; <nl> bool bHasNoConnection = false ; <nl> void CAudioAssetsManager : : UpdateAssetConnectionStates ( CAudioAsset * pAsset ) <nl> pAsset - > SetHasConnection ( ! bHasNoConnection ) ; <nl> pAsset - > SetHasControl ( bHasControl ) ; <nl> } <nl> - else if ( pAsset - > GetType ( ) ! = EItemType : : eItemType_Invalid ) <nl> + else if ( type ! = EItemType : : Invalid ) <nl> { <nl> - CAudioControl * pControl = static_cast < CAudioControl * > ( pAsset ) ; <nl> + CAudioControl * const pControl = static_cast < CAudioControl * > ( pAsset ) ; <nl> <nl> if ( pControl ! = nullptr ) <nl> { <nl> void CAudioAssetsManager : : UpdateAssetConnectionStates ( CAudioAsset * pAsset ) <nl> } <nl> } <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioAssetsManager : : MoveItems ( CAudioAsset * pParent , std : : vector < CAudioAsset * > const & items ) <nl> + void CAudioAssetsManager : : MoveItems ( CAudioAsset * const pParent , std : : vector < CAudioAsset * > const & items ) <nl> { <nl> if ( pParent ! = nullptr ) <nl> { <nl> void CAudioAssetsManager : : MoveItems ( CAudioAsset * pParent , std : : vector < CAudioAsse <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioAssetsManager : : CreateAndConnectImplItems ( IAudioSystemItem * pImplItem , CAudioAsset * pParent ) <nl> + void CAudioAssetsManager : : CreateAndConnectImplItems ( IAudioSystemItem * const pImplItem , CAudioAsset * const pParent ) <nl> { <nl> signalItemAboutToBeAdded ( pParent ) ; <nl> CAudioAsset * pItem = CreateAndConnectImplItemsRecursively ( pImplItem , pParent ) ; <nl> void CAudioAssetsManager : : CreateAndConnectImplItems ( IAudioSystemItem * pImplItem , <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CAudioAsset * CAudioAssetsManager : : CreateAndConnectImplItemsRecursively ( IAudioSystemItem * pImplItem , CAudioAsset * pParent ) <nl> + CAudioAsset * CAudioAssetsManager : : CreateAndConnectImplItemsRecursively ( IAudioSystemItem * const pImplItem , CAudioAsset * const pParent ) <nl> { <nl> CAudioAsset * pItem = nullptr ; <nl> <nl> / / Create the new control and connect it to the one dragged in externally <nl> - IAudioSystemEditor * pImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> + IAudioSystemEditor * const pImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> <nl> string name = pImplItem - > GetName ( ) ; <nl> EItemType const type = pImpl - > ImplTypeToATLType ( pImplItem - > GetType ( ) ) ; <nl> <nl> - if ( type ! = EItemType : : eItemType_Invalid ) <nl> + if ( type ! = EItemType : : Invalid ) <nl> { <nl> PathUtil : : RemoveExtension ( name ) ; <nl> <nl> - if ( type ! = eItemType_State ) <nl> + if ( type ! = EItemType : : State ) <nl> { <nl> name = Utils : : GenerateUniqueControlName ( name , type , * this ) ; <nl> } <nl> CAudioAsset * CAudioAssetsManager : : CreateAndConnectImplItemsRecursively ( IAudioSys <nl> pParent - > AddChild ( pControl ) ; <nl> m_controls . push_back ( pControl ) ; <nl> <nl> - ConnectionPtr pAudioConnection = pImpl - > CreateConnectionToControl ( pControl - > GetType ( ) , pImplItem ) ; <nl> + ConnectionPtr const pAudioConnection = pImpl - > CreateConnectionToControl ( pControl - > GetType ( ) , pImplItem ) ; <nl> <nl> if ( pAudioConnection ) <nl> { <nl> CAudioAsset * CAudioAssetsManager : : CreateAndConnectImplItemsRecursively ( IAudioSys <nl> else <nl> { <nl> / / If the type of the control is invalid then it must be a folder or container <nl> - name = Utils : : GenerateUniqueName ( name , EItemType : : eItemType_Folder , pParent ) ; <nl> - CAudioFolder * pFolder = new CAudioFolder ( name ) ; <nl> + name = Utils : : GenerateUniqueName ( name , EItemType : : Folder , pParent ) ; <nl> + CAudioFolder * const pFolder = new CAudioFolder ( name ) ; <nl> pParent - > AddChild ( pFolder ) ; <nl> pFolder - > SetParent ( pParent ) ; <nl> <nl> string GenerateUniqueLibraryName ( string const & name , CAudioAssetsManager const & <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - string GenerateUniqueControlName ( string const & name , EItemType type , CAudioAssetsManager const & assetManager ) <nl> + string GenerateUniqueControlName ( string const & name , EItemType const type , CAudioAssetsManager const & assetManager ) <nl> { <nl> CAudioAssetsManager : : Controls const & controls ( assetManager . GetControls ( ) ) ; <nl> std : : vector < string > names ; <nl> string GenerateUniqueControlName ( string const & name , EItemType type , CAudioAsset <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CAudioAsset * GetParentLibrary ( CAudioAsset * pAsset ) <nl> { <nl> - while ( pAsset & & pAsset - > GetType ( ) ! = EItemType : : eItemType_Library ) <nl> + while ( pAsset & & ( pAsset - > GetType ( ) ! = EItemType : : Library ) ) <nl> { <nl> pAsset = pAsset - > GetParent ( ) ; <nl> } <nl> CAudioAsset * GetParentLibrary ( CAudioAsset * pAsset ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void SelectTopLevelAncestors ( std : : vector < CAudioAsset * > const & source , std : : vector < CAudioAsset * > & dest ) <nl> { <nl> - for ( auto pItem : source ) <nl> + for ( auto const pItem : source ) <nl> { <nl> / / Check if item has ancestors that are also selected <nl> bool bAncestorAlsoSelected = false ; <nl> <nl> - for ( auto pOtherItem : source ) <nl> + for ( auto const pOtherItem : source ) <nl> { <nl> if ( pItem ! = pOtherItem ) <nl> { <nl> void SelectTopLevelAncestors ( std : : vector < CAudioAsset * > const & source , std : : vecto <nl> { <nl> break ; <nl> } <nl> + <nl> pParent = pParent - > GetParent ( ) ; <nl> } <nl> <nl> void SelectTopLevelAncestors ( std : : vector < CAudioAsset * > const & source , std : : vecto <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> string const & GetAssetFolder ( ) <nl> { <nl> - static string path = AUDIO_SYSTEM_DATA_ROOT CRY_NATIVE_PATH_SEPSTR " ace " CRY_NATIVE_PATH_SEPSTR ; <nl> + static string const path = AUDIO_SYSTEM_DATA_ROOT CRY_NATIVE_PATH_SEPSTR " ace " CRY_NATIVE_PATH_SEPSTR ; <nl> return path ; <nl> } <nl> } / / namespace Utils <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioAssetsManager . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioAssetsManager . h <nl> <nl> <nl> # pragma once <nl> <nl> - # include < CryString / CryString . h > <nl> # include " AudioAssets . h " <nl> + <nl> # include < IAudioConnection . h > <nl> # include < ACETypes . h > <nl> + # include < CryString / CryString . h > <nl> # include < CrySandbox / CrySignal . h > <nl> # include < array > <nl> + <nl> # include < QVariant > <nl> <nl> namespace ACE <nl> class CAudioAssetsManager <nl> size_t GetLibraryCount ( ) const { return m_audioLibraries . size ( ) ; } <nl> <nl> / / <nl> - CAudioAsset * CreateFolder ( string const & name , CAudioAsset * pParent = nullptr ) ; <nl> - CAudioControl * CreateControl ( string const & controlName , EItemType type , CAudioAsset * pParent = nullptr ) ; <nl> - void DeleteItem ( CAudioAsset * pItem ) ; <nl> + CAudioAsset * CreateFolder ( string const & name , CAudioAsset * const pParent = nullptr ) ; <nl> + CAudioControl * CreateControl ( string const & controlName , EItemType const type , CAudioAsset * const pParent = nullptr ) ; <nl> + void DeleteItem ( CAudioAsset * const pItem ) ; <nl> <nl> - CAudioControl * GetControlByID ( CID id ) const ; <nl> + CAudioControl * GetControlByID ( CID const id ) const ; <nl> CAudioControl * FindControl ( string const & controlName , EItemType const type , CAudioAsset * const pParent = nullptr ) const ; <nl> <nl> using Controls = std : : vector < CAudioControl * > ; <nl> class CAudioAssetsManager <nl> <nl> / / Scope <nl> void ClearScopes ( ) ; <nl> - void AddScope ( string const & name , bool bLocalOnly = false ) ; <nl> + void AddScope ( string const & name , bool const bLocalOnly = false ) ; <nl> bool ScopeExists ( string const & name ) const ; <nl> Scope GetScope ( string const & name ) const ; <nl> - SScopeInfo GetScopeInfo ( Scope id ) const ; <nl> + SScopeInfo GetScopeInfo ( Scope const id ) const ; <nl> void GetScopeInfoList ( ScopeInfoList & scopeList ) const ; <nl> <nl> / / Helper functions <nl> void ClearAllConnections ( ) ; <nl> void ReloadAllConnections ( ) ; <nl> - void MoveItems ( CAudioAsset * pParent , std : : vector < CAudioAsset * > const & items ) ; <nl> - void CreateAndConnectImplItems ( IAudioSystemItem * pImplItem , CAudioAsset * pParent ) ; <nl> + void MoveItems ( CAudioAsset * const pParent , std : : vector < CAudioAsset * > const & items ) ; <nl> + void CreateAndConnectImplItems ( IAudioSystemItem * const pImplItem , CAudioAsset * const pParent ) ; <nl> <nl> - bool IsTypeDirty ( EItemType eType ) ; <nl> + bool IsTypeDirty ( EItemType const type ) ; <nl> bool IsDirty ( ) ; <nl> void ClearDirtyFlags ( ) ; <nl> bool IsLoading ( ) const { return m_bLoading ; } <nl> <nl> - void SetAssetModified ( CAudioAsset * pAsset ) ; <nl> + void SetAssetModified ( CAudioAsset * const pAsset ) ; <nl> <nl> void UpdateAllConnectionStates ( ) ; <nl> void UpdateLibraryConnectionStates ( CAudioAsset * pAsset ) ; <nl> - void UpdateAssetConnectionStates ( CAudioAsset * pAsset ) ; <nl> + void UpdateAssetConnectionStates ( CAudioAsset * const pAsset ) ; <nl> <nl> / / Dirty flags signal <nl> CCrySignal < void ( bool ) > signalIsDirty ; <nl> class CAudioAssetsManager <nl> <nl> private : <nl> <nl> - CAudioAsset * CreateAndConnectImplItemsRecursively ( IAudioSystemItem * pImplItem , CAudioAsset * pParent ) ; <nl> - void OnControlAboutToBeModified ( CAudioControl * pControl ) ; <nl> - void OnControlModified ( CAudioControl * pControl ) ; <nl> - void OnConnectionAdded ( CAudioControl * pControl , IAudioSystemItem * pMiddlewareControl ) ; <nl> - void OnConnectionRemoved ( CAudioControl * pControl , IAudioSystemItem * pMiddlewareControl ) ; <nl> + CAudioAsset * CreateAndConnectImplItemsRecursively ( IAudioSystemItem * const pImplItem , CAudioAsset * const pParent ) ; <nl> + void OnControlAboutToBeModified ( CAudioControl * const pControl ) ; <nl> + void OnControlModified ( CAudioControl * const pControl ) ; <nl> + void OnConnectionAdded ( CAudioControl * const pControl , IAudioSystemItem * const pMiddlewareControl ) ; <nl> + void OnConnectionRemoved ( CAudioControl * const pControl , IAudioSystemItem * const pMiddlewareControl ) ; <nl> <nl> CID GenerateUniqueId ( ) { return m_nextId + + ; } <nl> <nl> class CAudioAssetsManager <nl> static CID m_nextId ; <nl> Controls m_controls ; <nl> std : : map < Scope , SScopeInfo > m_scopeMap ; <nl> - std : : array < bool , 8 > m_bControlTypeModified { false , false , false , false , false , false , false , false } ; <nl> + std : : array < bool , 8 > m_bControlTypeModified { false , false , false , false , false , false , false , false } ; / / Replace this . Possibly with a QList . <nl> bool m_bLoading = false ; <nl> } ; <nl> <nl> namespace Utils <nl> Scope GetGlobalScope ( ) ; <nl> string GenerateUniqueName ( string const & name , EItemType const type , CAudioAsset * const pParent ) ; <nl> string GenerateUniqueLibraryName ( string const & name , CAudioAssetsManager const & assetManager ) ; <nl> - string GenerateUniqueControlName ( string const & name , EItemType type , CAudioAssetsManager const & assetManager ) ; <nl> + string GenerateUniqueControlName ( string const & name , EItemType const type , CAudioAssetsManager const & assetManager ) ; <nl> CAudioAsset * GetParentLibrary ( CAudioAsset * pAsset ) ; <nl> void SelectTopLevelAncestors ( std : : vector < CAudioAsset * > const & source , std : : vector < CAudioAsset * > & dest ) ; <nl> string const & GetAssetFolder ( ) ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsEditorPlugin . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsEditorPlugin . cpp <nl> <nl> # include " StdAfx . h " <nl> # include " AudioControlsEditorPlugin . h " <nl> <nl> - # include < CryCore / Platform / platform_impl . inl > <nl> - <nl> - # include " IUndoManager . h " <nl> - # include " QtViewPane . h " <nl> + # include " AudioAssets . h " <nl> # include " AudioControlsEditorWindow . h " <nl> - # include " IResourceSelectorHost . h " <nl> # include " AudioControlsLoader . h " <nl> # include " AudioControlsWriter . h " <nl> - # include " AudioAssets . h " <nl> + # include " ImplementationManager . h " <nl> + <nl> # include < IAudioSystemEditor . h > <nl> # include < CryAudio / IAudioSystem . h > <nl> # include < CryAudio / IObject . h > <nl> # include < CryMath / Cry_Camera . h > <nl> - <nl> # include < CrySystem / File / CryFile . h > <nl> # include < CryString / CryPath . h > <nl> - # include " ImplementationManager . h " <nl> + # include < CryCore / Platform / platform_impl . inl > <nl> + # include < IUndoManager . h > <nl> + # include < QtViewPane . h > <nl> + # include < IResourceSelectorHost . h > <nl> <nl> REGISTER_PLUGIN ( ACE : : CAudioControlsEditorPlugin ) ; <nl> <nl> - using namespace ACE ; <nl> - using namespace PathUtil ; <nl> - <nl> + namespace ACE <nl> + { <nl> CAudioAssetsManager CAudioControlsEditorPlugin : : s_assetsManager ; <nl> std : : set < string > CAudioControlsEditorPlugin : : s_currentFilenames ; <nl> CryAudio : : IObject * CAudioControlsEditorPlugin : : s_pIAudioObject = nullptr ; <nl> CryAudio : : ControlId CAudioControlsEditorPlugin : : s_audioTriggerId = CryAudio : : InvalidControlId ; <nl> - ACE : : CImplementationManager CAudioControlsEditorPlugin : : s_implementationManager ; <nl> - uint CAudioControlsEditorPlugin : : s_loadingErrorMask ; <nl> + CImplementationManager CAudioControlsEditorPlugin : : s_implementationManager ; <nl> + EErrorCode CAudioControlsEditorPlugin : : s_loadingErrorMask ; <nl> CCrySignal < void ( ) > CAudioControlsEditorPlugin : : signalAboutToLoad ; <nl> CCrySignal < void ( ) > CAudioControlsEditorPlugin : : signalLoaded ; <nl> CCrySignal < void ( ) > CAudioControlsEditorPlugin : : signalAboutToSave ; <nl> CAudioControlsEditorPlugin : : ~ CAudioControlsEditorPlugin ( ) <nl> void CAudioControlsEditorPlugin : : SaveModels ( ) <nl> { <nl> signalAboutToSave ( ) ; <nl> - ACE : : IAudioSystemEditor * pImpl = s_implementationManager . GetImplementation ( ) ; <nl> + IAudioSystemEditor * pImpl = s_implementationManager . GetImplementation ( ) ; <nl> <nl> if ( pImpl ) <nl> { <nl> CAudioControlsWriter writer ( & s_assetsManager , pImpl , s_currentFilenames ) ; <nl> } <nl> <nl> - s_loadingErrorMask = static_cast < uint > ( EErrorCode : : eErrorCode_NoError ) ; <nl> + s_loadingErrorMask = EErrorCode : : NoError ; <nl> signalSaved ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControlsEditorPlugin : : ReloadModels ( bool bReloadImplementation ) <nl> + void CAudioControlsEditorPlugin : : ReloadModels ( bool const bReloadImplementation ) <nl> { <nl> / / Do not call signalAboutToLoad and signalLoaded in here ! <nl> GetIEditor ( ) - > GetIUndoManager ( ) - > Suspend ( ) ; <nl> <nl> - ACE : : IAudioSystemEditor * const pImpl = s_implementationManager . GetImplementation ( ) ; <nl> + IAudioSystemEditor * const pImpl = s_implementationManager . GetImplementation ( ) ; <nl> <nl> if ( pImpl ! = nullptr ) <nl> { <nl> CAudioAssetsManager * CAudioControlsEditorPlugin : : GetAssetsManager ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - ACE : : IAudioSystemEditor * CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) <nl> + IAudioSystemEditor * CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) <nl> { <nl> return s_implementationManager . GetImplementation ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControlsEditorPlugin : : ExecuteTrigger ( const string & sTriggerName ) <nl> + void CAudioControlsEditorPlugin : : ExecuteTrigger ( string const & sTriggerName ) <nl> { <nl> - if ( ! sTriggerName . empty ( ) & & s_pIAudioObject ! = nullptr ) <nl> + if ( ! sTriggerName . empty ( ) & & ( s_pIAudioObject ! = nullptr ) ) <nl> { <nl> StopTriggerExecution ( ) ; <nl> - const CCamera & camera = GetIEditor ( ) - > GetSystem ( ) - > GetViewCamera ( ) ; <nl> - const Matrix34 & cameraMatrix = camera . GetMatrix ( ) ; <nl> + CCamera const & camera = GetIEditor ( ) - > GetSystem ( ) - > GetViewCamera ( ) ; <nl> + Matrix34 const & cameraMatrix = camera . GetMatrix ( ) ; <nl> s_pIAudioObject - > SetTransformation ( cameraMatrix ) ; <nl> s_audioTriggerId = CryAudio : : StringToId ( sTriggerName . c_str ( ) ) ; <nl> s_pIAudioObject - > ExecuteTrigger ( s_audioTriggerId ) ; <nl> void CAudioControlsEditorPlugin : : ExecuteTrigger ( const string & sTriggerName ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsEditorPlugin : : StopTriggerExecution ( ) <nl> { <nl> - if ( s_pIAudioObject & & s_audioTriggerId ! = CryAudio : : InvalidControlId ) <nl> + if ( s_pIAudioObject & & ( s_audioTriggerId ! = CryAudio : : InvalidControlId ) ) <nl> { <nl> s_pIAudioObject - > StopTrigger ( s_audioTriggerId ) ; <nl> s_audioTriggerId = CryAudio : : InvalidControlId ; <nl> CImplementationManager * CAudioControlsEditorPlugin : : GetImplementationManger ( ) <nl> { <nl> return & s_implementationManager ; <nl> } <nl> + } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsEditorPlugin . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsEditorPlugin . h <nl> <nl> <nl> # pragma once <nl> <nl> - # include < IEditor . h > <nl> # include < IPlugin . h > <nl> + # include < IEditor . h > <nl> + <nl> # include " AudioAssetsManager . h " <nl> - # include " SystemControlsModel . h " <nl> + <nl> # include < IAudioSystemEditor . h > <nl> # include < CryAudio / IAudioInterfacesCommonData . h > <nl> # include < CrySandbox / CrySignal . h > <nl> class CAudioControlsEditorPlugin final : public IPlugin , public ISystemEventList <nl> const char * GetPluginDescription ( ) override { return " The Audio Controls Editor enables browsing and configuring audio events exposed from the audio middleware " ; } <nl> <nl> static void SaveModels ( ) ; <nl> - static void ReloadModels ( bool bReloadImplementation ) ; <nl> + static void ReloadModels ( bool const bReloadImplementation ) ; <nl> static void ReloadScopes ( ) ; <nl> static CAudioAssetsManager * GetAssetsManager ( ) ; <nl> static CImplementationManager * GetImplementationManger ( ) ; <nl> static IAudioSystemEditor * GetAudioSystemEditorImpl ( ) ; <nl> - static void ExecuteTrigger ( const string & sTriggerName ) ; <nl> + static void ExecuteTrigger ( string const & sTriggerName ) ; <nl> static void StopTriggerExecution ( ) ; <nl> - static uint GetLoadingErrorMask ( ) { return s_loadingErrorMask ; } <nl> + static EErrorCode GetLoadingErrorMask ( ) { return s_loadingErrorMask ; } <nl> <nl> static CCrySignal < void ( ) > signalAboutToLoad ; <nl> static CCrySignal < void ( ) > signalLoaded ; <nl> class CAudioControlsEditorPlugin final : public IPlugin , public ISystemEventList <nl> static CryAudio : : ControlId s_audioTriggerId ; <nl> <nl> static CImplementationManager s_implementationManager ; <nl> - static uint s_loadingErrorMask ; <nl> + static EErrorCode s_loadingErrorMask ; <nl> } ; <nl> } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsEditorUI . qrc <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsEditorUI . qrc <nl> <nl> < RCC > <nl> < qresource prefix = " / " > <nl> - < file > Icons / Bank . ico < / file > <nl> < file > Icons / Environment . ico < / file > <nl> - < file > Icons / Folder . ico < / file > <nl> - < file > Icons / Property . ico < / file > <nl> < file > Icons / Parameter . ico < / file > <nl> - < file > Icons / Search . ico < / file > <nl> < file > Icons / Switch . ico < / file > <nl> < file > Icons / Trigger . ico < / file > <nl> < file > Icons / Preload . ico < / file > <nl> - < file > Icons / Load . ico < / file > <nl> - < file > Icons / Save . ico < / file > <nl> - < file > Icons / Options . ico < / file > <nl> + < file > Icons / State . ico < / file > <nl> < / qresource > <nl> < / RCC > <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsEditorWindow . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsEditorWindow . cpp <nl> <nl> <nl> # include " StdAfx . h " <nl> # include " AudioControlsEditorWindow . h " <nl> + <nl> # include " AudioControlsEditorPlugin . h " <nl> # include " SystemControlsEditorIcons . h " <nl> # include " PreferencesDialog . h " <nl> # include " AudioAssetsManager . h " <nl> - # include < CryAudio / IAudioSystem . h > <nl> - # include " AudioControlsEditorUndo . h " <nl> + # include " ImplementationManager . h " <nl> # include " SystemControlsWidget . h " <nl> # include " PropertiesWidget . h " <nl> # include " MiddlewareDataWidget . h " <nl> - # include " AdvancedTreeView . h " <nl> + # include " AudioTreeView . h " <nl> # include " FileMonitor . h " <nl> + # include " AudioControlsEditorUndo . h " <nl> + <nl> + # include < CryAudio / IAudioSystem . h > <nl> # include < CrySystem / File / CryFile . h > <nl> # include < CrySystem / ISystem . h > <nl> # include < CryString / CryPath . h > <nl> - # include " ImplementationManager . h " <nl> - # include " QtUtil . h " <nl> + # include < QtUtil . h > <nl> # include < CryIcon . h > <nl> # include " Controls / QuestionDialog . h " <nl> <nl> - # include < QApplication > <nl> - # include < QVBoxLayout > <nl> # include < QAction > <nl> - # include < QToolBar > <nl> + # include < QGuiApplication > <nl> # include < QKeyEvent > <nl> + # include < QToolBar > <nl> + # include < QVBoxLayout > <nl> <nl> namespace ACE <nl> { <nl> CAudioControlsEditorWindow : : CAudioControlsEditorWindow ( ) <nl> setAttribute ( Qt : : WA_DeleteOnClose ) ; <nl> setObjectName ( GetEditorName ( ) ) ; <nl> <nl> - QVBoxLayout * pWindowLayout = new QVBoxLayout ( ) ; <nl> + QVBoxLayout * const pWindowLayout = new QVBoxLayout ( ) ; <nl> pWindowLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ; <nl> SetContent ( pWindowLayout ) ; <nl> <nl> CAudioControlsEditorWindow : : CAudioControlsEditorWindow ( ) <nl> m_pAssetsManager - > UpdateAllConnectionStates ( ) ; <nl> CheckErrorMask ( ) ; <nl> <nl> - m_pMonitorSystem = std : : make_unique < ACE : : CFileMonitorSystem > ( this , 500 ) ; <nl> - m_pMonitorMiddleware = std : : make_unique < ACE : : CFileMonitorMiddleware > ( this , 500 ) ; <nl> + m_pMonitorSystem = std : : make_unique < CFileMonitorSystem > ( this , 500 ) ; <nl> + m_pMonitorMiddleware = std : : make_unique < CFileMonitorMiddleware > ( this , 500 ) ; <nl> <nl> CAudioControlsEditorPlugin : : signalAboutToSave . Connect ( [ & ] ( ) <nl> { <nl> CAudioControlsEditorWindow : : CAudioControlsEditorWindow ( ) <nl> m_pMonitorSystem - > EnableDelayed ( ) ; <nl> } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> <nl> - m_pAssetsManager - > signalIsDirty . Connect ( [ & ] ( bool bDirty ) <nl> + m_pAssetsManager - > signalIsDirty . Connect ( [ & ] ( bool const bDirty ) <nl> { <nl> m_pSaveAction - > setEnabled ( bDirty ) ; <nl> } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> CAudioControlsEditorWindow : : ~ CAudioControlsEditorWindow ( ) <nl> GetIEditor ( ) - > UnregisterNotifyListener ( this ) ; <nl> } <nl> <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControlsEditorWindow : : keyPressEvent ( QKeyEvent * pEvent ) <nl> - { <nl> - if ( ! m_pSystemControlsWidget - > IsEditing ( ) ) <nl> - { <nl> - if ( ( pEvent - > key ( ) = = Qt : : Key_S ) & & ( pEvent - > modifiers ( ) = = Qt : : ControlModifier ) ) <nl> - { <nl> - Save ( ) ; <nl> - } <nl> - else if ( ( pEvent - > key ( ) = = Qt : : Key_Z ) & & ( pEvent - > modifiers ( ) & Qt : : ControlModifier ) ) <nl> - { <nl> - if ( pEvent - > modifiers ( ) & Qt : : ShiftModifier ) <nl> - { <nl> - GetIEditor ( ) - > GetIUndoManager ( ) - > Redo ( ) ; <nl> - } <nl> - else <nl> - { <nl> - GetIEditor ( ) - > GetIUndoManager ( ) - > Undo ( ) ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - QWidget : : keyPressEvent ( pEvent ) ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControlsEditorWindow : : closeEvent ( QCloseEvent * pEvent ) <nl> - { <nl> - if ( m_pAssetsManager & & m_pAssetsManager - > IsDirty ( ) ) <nl> - { <nl> - CQuestionDialog messageBox ; <nl> - messageBox . SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( " There are unsaved changes . \ nDo you want to save your changes ? " ) , QDialogButtonBox : : Save | QDialogButtonBox : : Discard | QDialogButtonBox : : Cancel , QDialogButtonBox : : Save ) ; <nl> - <nl> - switch ( messageBox . Execute ( ) ) <nl> - { <nl> - case QDialogButtonBox : : Save : <nl> - QApplication : : setOverrideCursor ( Qt : : WaitCursor ) ; <nl> - Save ( ) ; <nl> - QApplication : : restoreOverrideCursor ( ) ; <nl> - pEvent - > accept ( ) ; <nl> - break ; <nl> - case QDialogButtonBox : : Discard : <nl> - { <nl> - ACE : : IAudioSystemEditor * pAudioSystemEditorImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> - if ( pAudioSystemEditorImpl ) <nl> - { <nl> - pAudioSystemEditorImpl - > Reload ( false ) ; <nl> - } <nl> - <nl> - CAudioControlsEditorPlugin : : signalAboutToLoad ( ) ; <nl> - CAudioControlsEditorPlugin : : ReloadModels ( false ) ; <nl> - CAudioControlsEditorPlugin : : signalLoaded ( ) ; <nl> - <nl> - pEvent - > accept ( ) ; <nl> - } <nl> - break ; <nl> - default : <nl> - pEvent - > ignore ( ) ; <nl> - break ; <nl> - } <nl> - } <nl> - else <nl> - { <nl> - pEvent - > accept ( ) ; <nl> - } <nl> - } <nl> - <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsEditorWindow : : InitMenu ( ) <nl> { <nl> void CAudioControlsEditorWindow : : InitMenu ( ) <nl> AddToMenu ( items , sizeof ( items ) / sizeof ( CEditor : : MenuItems ) ) ; <nl> <nl> CAbstractMenu * const pMenuEdit = GetMenu ( MenuItems : : EditMenu ) ; <nl> - auto pPreferencesAction = pMenuEdit - > CreateAction ( tr ( " Preferences . . . " ) ) ; <nl> + QAction * const pPreferencesAction = pMenuEdit - > CreateAction ( tr ( " Preferences . . . " ) ) ; <nl> QObject : : connect ( pPreferencesAction , & QAction : : triggered , this , & CAudioControlsEditorWindow : : OnPreferencesDialog ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControlsEditorWindow : : InitToolbar ( QVBoxLayout * pWindowLayout ) <nl> + void CAudioControlsEditorWindow : : InitToolbar ( QVBoxLayout * const pWindowLayout ) <nl> { <nl> - QHBoxLayout * pToolBarsLayout = new QHBoxLayout ( ) ; <nl> + QHBoxLayout * const pToolBarsLayout = new QHBoxLayout ( ) ; <nl> pToolBarsLayout - > setDirection ( QBoxLayout : : LeftToRight ) ; <nl> pToolBarsLayout - > setSizeConstraint ( QLayout : : SetMaximumSize ) ; <nl> <nl> { <nl> - QToolBar * pToolBar = new QToolBar ( " ACE Tools " ) ; <nl> + QToolBar * const pToolBar = new QToolBar ( " ACE Tools " ) ; <nl> <nl> { <nl> m_pSaveAction = pToolBar - > addAction ( CryIcon ( " icons : General / File_Save . ico " ) , QString ( ) ) ; <nl> - m_pSaveAction - > setToolTip ( tr ( " Save all changes . " ) ) ; <nl> + m_pSaveAction - > setToolTip ( tr ( " Save all changes " ) ) ; <nl> m_pSaveAction - > setEnabled ( false ) ; <nl> QObject : : connect ( m_pSaveAction , & QAction : : triggered , this , & CAudioControlsEditorWindow : : Save ) ; <nl> } <nl> <nl> { <nl> - QAction * pReloadAction = pToolBar - > addAction ( CryIcon ( " icons : General / Reload . ico " ) , QString ( ) ) ; <nl> - pReloadAction - > setToolTip ( tr ( " Reload all ACE and middleware files . " ) ) ; <nl> + QAction * const pReloadAction = pToolBar - > addAction ( CryIcon ( " icons : General / Reload . ico " ) , QString ( ) ) ; <nl> + pReloadAction - > setToolTip ( tr ( " Reload all ACE and middleware files " ) ) ; <nl> QObject : : connect ( pReloadAction , & QAction : : triggered , this , & CAudioControlsEditorWindow : : Reload ) ; <nl> } <nl> <nl> CSystemControlsWidget * CAudioControlsEditorWindow : : CreateSystemControlsWidget ( ) <nl> QObject : : connect ( pSystemControlsWidget , & CSystemControlsWidget : : StartTextFiltering , this , & CAudioControlsEditorWindow : : OnStartTextFiltering ) ; <nl> QObject : : connect ( pSystemControlsWidget , & CSystemControlsWidget : : StopTextFiltering , this , & CAudioControlsEditorWindow : : OnStopTextFiltering ) ; <nl> QObject : : connect ( pSystemControlsWidget , & QObject : : destroyed , this , & CAudioControlsEditorWindow : : OnSystemControlsWidgetDestruction ) ; <nl> + <nl> return pSystemControlsWidget ; <nl> } <nl> <nl> CPropertiesWidget * CAudioControlsEditorWindow : : CreatePropertiesWidget ( ) <nl> QObject : : connect ( this , & CAudioControlsEditorWindow : : OnStartTextFiltering , pPropertiesWidget , & CPropertiesWidget : : BackupTreeViewStates ) ; <nl> QObject : : connect ( this , & CAudioControlsEditorWindow : : OnStopTextFiltering , pPropertiesWidget , & CPropertiesWidget : : RestoreTreeViewStates ) ; <nl> QObject : : connect ( pPropertiesWidget , & QObject : : destroyed , this , & CAudioControlsEditorWindow : : OnPropertiesWidgetDestruction ) ; <nl> + <nl> return pPropertiesWidget ; <nl> } <nl> <nl> CMiddlewareDataWidget * CAudioControlsEditorWindow : : CreateMiddlewareDataWidget ( ) <nl> } <nl> <nl> QObject : : connect ( pMiddlewareDataWidget , & QObject : : destroyed , this , & CAudioControlsEditorWindow : : OnMiddlewareDataWidgetDestruction ) ; <nl> + <nl> return pMiddlewareDataWidget ; <nl> } <nl> <nl> void CAudioControlsEditorWindow : : CreateDefaultLayout ( CDockableContainer * pSender <nl> <nl> pSender - > SpawnWidget ( " Audio System Controls " ) ; <nl> pSender - > SpawnWidget ( " Properties " , QToolWindowAreaReference : : VSplitRight ) ; <nl> - pSender - > SpawnWidget ( " Middleware Data " , QToolWindowAreaReference : : VSplitRight ) ; <nl> + QWidget * pWidget = pSender - > SpawnWidget ( " Middleware Data " , QToolWindowAreaReference : : VSplitRight ) ; <nl> + pSender - > SetSplitterSizes ( pWidget , { 1 , 1 , 1 } ) ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + void CAudioControlsEditorWindow : : closeEvent ( QCloseEvent * pEvent ) <nl> + { <nl> + if ( m_pAssetsManager & & m_pAssetsManager - > IsDirty ( ) ) <nl> + { <nl> + CQuestionDialog * messageBox = new CQuestionDialog ( ) ; <nl> + messageBox - > SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( " There are unsaved changes . \ nDo you want to save your changes ? " ) , QDialogButtonBox : : Save | QDialogButtonBox : : Discard | QDialogButtonBox : : Cancel , QDialogButtonBox : : Save ) ; <nl> + <nl> + switch ( messageBox - > Execute ( ) ) <nl> + { <nl> + case QDialogButtonBox : : Save : <nl> + Save ( ) ; <nl> + pEvent - > accept ( ) ; <nl> + break ; <nl> + case QDialogButtonBox : : Discard : <nl> + { <nl> + IAudioSystemEditor * pAudioSystemEditorImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> + <nl> + if ( pAudioSystemEditorImpl ) <nl> + { <nl> + pAudioSystemEditorImpl - > Reload ( false ) ; <nl> + } <nl> + <nl> + CAudioControlsEditorPlugin : : signalAboutToLoad ( ) ; <nl> + CAudioControlsEditorPlugin : : ReloadModels ( false ) ; <nl> + CAudioControlsEditorPlugin : : signalLoaded ( ) ; <nl> + <nl> + pEvent - > accept ( ) ; <nl> + } <nl> + break ; <nl> + default : <nl> + pEvent - > ignore ( ) ; <nl> + break ; <nl> + } <nl> + } <nl> + else <nl> + { <nl> + pEvent - > accept ( ) ; <nl> + } <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + void CAudioControlsEditorWindow : : keyPressEvent ( QKeyEvent * pEvent ) <nl> + { <nl> + if ( ! m_pSystemControlsWidget - > IsEditing ( ) ) <nl> + { <nl> + if ( ( pEvent - > key ( ) = = Qt : : Key_S ) & & ( pEvent - > modifiers ( ) = = Qt : : ControlModifier ) ) <nl> + { <nl> + Save ( ) ; <nl> + } <nl> + else if ( ( pEvent - > key ( ) = = Qt : : Key_Z ) & & ( pEvent - > modifiers ( ) & Qt : : ControlModifier ) ) <nl> + { <nl> + if ( pEvent - > modifiers ( ) & Qt : : ShiftModifier ) <nl> + { <nl> + GetIEditor ( ) - > GetIUndoManager ( ) - > Redo ( ) ; <nl> + } <nl> + else <nl> + { <nl> + GetIEditor ( ) - > GetIUndoManager ( ) - > Undo ( ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + QWidget : : keyPressEvent ( pEvent ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsEditorWindow : : Reload ( ) <nl> { <nl> if ( m_pAssetsManager ! = nullptr ) <nl> { <nl> + m_pMonitorSystem - > Disable ( ) ; <nl> + m_pMonitorMiddleware - > Disable ( ) ; <nl> + <nl> bool bReload = true ; <nl> <nl> if ( m_pAssetsManager - > IsDirty ( ) ) <nl> { <nl> - CQuestionDialog messageBox ; <nl> - messageBox . SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( " If you reload you will lose all your unsaved changes . \ nAre you sure you want to reload ? " ) , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : No ) ; <nl> - bReload = ( messageBox . Execute ( ) = = QDialogButtonBox : : Yes ) ; <nl> + CQuestionDialog * messageBox = new CQuestionDialog ( ) ; <nl> + messageBox - > SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( " If you reload you will lose all your unsaved changes . \ nAre you sure you want to reload ? " ) , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : No ) ; <nl> + bReload = ( messageBox - > Execute ( ) = = QDialogButtonBox : : Yes ) ; <nl> } <nl> <nl> if ( bReload ) <nl> { <nl> - m_pMonitorSystem - > Disable ( ) ; <nl> - m_pMonitorMiddleware - > Disable ( ) ; <nl> - <nl> + QGuiApplication : : setOverrideCursor ( Qt : : WaitCursor ) ; <nl> BackupTreeViewStates ( ) ; <nl> <nl> if ( m_pAssetsManager - > IsLoading ( ) ) <nl> void CAudioControlsEditorWindow : : Reload ( ) <nl> CheckErrorMask ( ) ; <nl> <nl> RestoreTreeViewStates ( ) ; <nl> - <nl> - m_pMonitorSystem - > Enable ( ) ; <nl> - m_pMonitorMiddleware - > Enable ( ) ; <nl> + QGuiApplication : : restoreOverrideCursor ( ) ; <nl> } <nl> + <nl> + m_pMonitorSystem - > Enable ( ) ; <nl> + m_pMonitorMiddleware - > Enable ( ) ; <nl> } <nl> } <nl> <nl> void CAudioControlsEditorWindow : : SaveBeforeImplementationChange ( ) <nl> { <nl> if ( m_pAssetsManager - > IsDirty ( ) ) <nl> { <nl> - CQuestionDialog messageBox ; <nl> - messageBox . SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( " Middleware implementation changed . \ nThere are unsaved changes . \ nDo you want to save before reloading ? " ) , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : No ) ; <nl> - <nl> - if ( messageBox . Execute ( ) = = QDialogButtonBox : : Yes ) <nl> + CQuestionDialog * messageBox = new CQuestionDialog ( ) ; <nl> + messageBox - > SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( " Middleware implementation changed . \ nThere are unsaved changes . \ nDo you want to save before reloading ? " ) , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : No ) ; <nl> + <nl> + if ( messageBox - > Execute ( ) = = QDialogButtonBox : : Yes ) <nl> { <nl> m_pAssetsManager - > ClearDirtyFlags ( ) ; <nl> Save ( ) ; <nl> void CAudioControlsEditorWindow : : SaveBeforeImplementationChange ( ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsEditorWindow : : CheckErrorMask ( ) <nl> { <nl> - uint const errorCodeMask = CAudioControlsEditorPlugin : : GetLoadingErrorMask ( ) ; <nl> + EErrorCode const errorCodeMask = CAudioControlsEditorPlugin : : GetLoadingErrorMask ( ) ; <nl> <nl> - if ( ( errorCodeMask & EErrorCode : : eErrorCode_UnkownPlatform ) ! = 0 ) <nl> + if ( ( errorCodeMask & EErrorCode : : UnkownPlatform ) ! = 0 ) <nl> { <nl> CQuestionDialog : : SWarning ( tr ( GetEditorName ( ) ) , tr ( " Audio Preloads reference an unknown platform . \ nSaving will permanently erase this data . " ) ) ; <nl> } <nl> - else if ( ( errorCodeMask & EErrorCode : : eErrorCode_NonMatchedActivityRadius ) ! = 0 ) <nl> + else if ( ( errorCodeMask & EErrorCode : : NonMatchedActivityRadius ) ! = 0 ) <nl> { <nl> IAudioSystemEditor const * const pAudioSystemImpl = CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > GetImplementation ( ) ; <nl> <nl> void CAudioControlsEditorWindow : : CheckErrorMask ( ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsEditorWindow : : Save ( ) <nl> { <nl> - bool bPreloadsChanged = m_pAssetsManager - > IsTypeDirty ( eItemType_Preload ) ; <nl> + bool bPreloadsChanged = m_pAssetsManager - > IsTypeDirty ( EItemType : : Preload ) ; <nl> + QGuiApplication : : setOverrideCursor ( Qt : : WaitCursor ) ; <nl> CAudioControlsEditorPlugin : : SaveModels ( ) ; <nl> UpdateAudioSystemData ( ) ; <nl> + QGuiApplication : : restoreOverrideCursor ( ) ; <nl> <nl> / / if preloads have been modified , ask the user if s / he wants to refresh the audio system <nl> if ( bPreloadsChanged ) <nl> { <nl> - CQuestionDialog messageBox ; <nl> + CQuestionDialog * messageBox = new CQuestionDialog ( ) ; <nl> + messageBox - > SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( " Preload requests have been modified . \ n \ nFor the new data to be loaded the audio system needs to be refreshed , this will stop all currently playing audio . Do you want to do this now ? . \ n \ nYou can always refresh manually at a later time through the Audio menu . " ) , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : No ) ; <nl> <nl> - messageBox . SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( " Preload requests have been modified . \ n \ nFor the new data to be loaded the audio system needs to be refreshed , this will stop all currently playing audio . Do you want to do this now ? . \ n \ nYou can always refresh manually at a later time through the Audio menu . " ) , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : No ) ; <nl> - <nl> - if ( messageBox . Execute ( ) = = QDialogButtonBox : : Yes ) <nl> + if ( messageBox - > Execute ( ) = = QDialogButtonBox : : Yes ) <nl> { <nl> + QGuiApplication : : setOverrideCursor ( Qt : : WaitCursor ) ; <nl> char const * szLevelName = GetIEditor ( ) - > GetLevelName ( ) ; <nl> <nl> if ( _stricmp ( szLevelName , " Untitled " ) = = 0 ) <nl> void CAudioControlsEditorWindow : : Save ( ) <nl> <nl> CryAudio : : SRequestUserData const data ( CryAudio : : ERequestFlags : : ExecuteBlocking ) ; <nl> gEnv - > pAudioSystem - > Refresh ( szLevelName , data ) ; <nl> + QGuiApplication : : restoreOverrideCursor ( ) ; <nl> } <nl> } <nl> <nl> void CAudioControlsEditorWindow : : OnEditorNotifyEvent ( EEditorNotifyEvent event ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAudioControlsEditorWindow : : FilterControlType ( EItemType type , bool bShow ) <nl> + void CAudioControlsEditorWindow : : FilterControlType ( EItemType const type , bool const bShow ) <nl> { <nl> - m_allowedTypes [ type ] = bShow ; <nl> + m_allowedTypes [ static_cast < int > ( type ) ] = bShow ; <nl> <nl> - if ( type = = eItemType_Switch ) <nl> + if ( type = = EItemType : : Switch ) <nl> { <nl> / / need to keep states and switches filtering in sync as we don ' t have a separate filtering for states , only for switches <nl> - m_allowedTypes [ eItemType_State ] = bShow ; <nl> + m_allowedTypes [ static_cast < int > ( EItemType : : State ) ] = bShow ; <nl> } <nl> <nl> if ( m_pMiddlewareDataWidget ! = nullptr ) <nl> void CAudioControlsEditorWindow : : ReloadSystemData ( ) <nl> { <nl> if ( m_pAssetsManager ! = nullptr ) <nl> { <nl> + m_pMonitorSystem - > Disable ( ) ; <nl> + <nl> bool bReload = true ; <nl> char const * messageText ; <nl> <nl> void CAudioControlsEditorWindow : : ReloadSystemData ( ) <nl> messageText = " External changes have been made to audio controls files . \ nDo you want to reload ? " ; <nl> } <nl> <nl> - CQuestionDialog messageBox ; <nl> - messageBox . SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( messageText ) , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : No ) ; <nl> - bReload = ( messageBox . Execute ( ) = = QDialogButtonBox : : Yes ) ; <nl> + CQuestionDialog * messageBox = new CQuestionDialog ( ) ; <nl> + messageBox - > SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( messageText ) , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : No ) ; <nl> + bReload = ( messageBox - > Execute ( ) = = QDialogButtonBox : : Yes ) ; <nl> <nl> if ( bReload ) <nl> { <nl> m_pAssetsManager - > ClearDirtyFlags ( ) ; <nl> Reload ( ) ; <nl> } <nl> + else <nl> + { <nl> + m_pMonitorSystem - > Enable ( ) ; <nl> + } <nl> } <nl> } <nl> <nl> void CAudioControlsEditorWindow : : ReloadMiddlewareData ( ) <nl> { <nl> if ( m_pAssetsManager - > IsDirty ( ) ) <nl> { <nl> + m_pMonitorMiddleware - > Disable ( ) ; <nl> + <nl> char const * messageText = " External changes have been made to middleware data . \ n \ nWarning : If middleware data gets refreshed without saving audio control files , unsaved connection changes will get lost ! \ n \ nDo you want to save before refreshing middleware data ? " ; <nl> - CQuestionDialog messageBox ; <nl> - messageBox . SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( messageText ) , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : Yes ) ; <nl> + CQuestionDialog * messageBox = new CQuestionDialog ( ) ; <nl> + messageBox - > SetupQuestion ( tr ( GetEditorName ( ) ) , tr ( messageText ) , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : Yes ) ; <nl> <nl> - if ( messageBox . Execute ( ) = = QDialogButtonBox : : Yes ) <nl> + if ( messageBox - > Execute ( ) = = QDialogButtonBox : : Yes ) <nl> { <nl> Save ( ) ; <nl> } <nl> + <nl> + m_pMonitorMiddleware - > Enable ( ) ; <nl> } <nl> } <nl> <nl> - IAudioSystemEditor * pAudioSystemImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> - <nl> + QGuiApplication : : setOverrideCursor ( Qt : : WaitCursor ) ; <nl> BackupTreeViewStates ( ) ; <nl> <nl> + IAudioSystemEditor * pAudioSystemImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> + <nl> if ( pAudioSystemImpl ) <nl> { <nl> CryWarning ( VALIDATOR_MODULE_EDITOR , VALIDATOR_COMMENT , " [ Audio Controls Editor ] Reloading audio implementation data " ) ; <nl> void CAudioControlsEditorWindow : : ReloadMiddlewareData ( ) <nl> } <nl> <nl> RestoreTreeViewStates ( ) ; <nl> + QGuiApplication : : restoreOverrideCursor ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsEditorWindow : : RestoreTreeViewStates ( ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsEditorWindow : : OnPreferencesDialog ( ) <nl> { <nl> - CPreferencesDialog * pPreferencesDialog = new CPreferencesDialog ( this ) ; <nl> + CPreferencesDialog * const pPreferencesDialog = new CPreferencesDialog ( this ) ; <nl> <nl> QObject : : connect ( pPreferencesDialog , & CPreferencesDialog : : ImplementationSettingsAboutToChange , [ & ] ( ) <nl> { <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsEditorWindow . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsEditorWindow . h <nl> private slots : <nl> private : <nl> <nl> void InitMenu ( ) ; <nl> - void InitToolbar ( QVBoxLayout * pWindowLayout ) ; <nl> + void InitToolbar ( QVBoxLayout * const pWindowLayout ) ; <nl> void RegisterWidgets ( ) ; <nl> void Reload ( ) ; <nl> void Save ( ) ; <nl> void SaveBeforeImplementationChange ( ) ; <nl> - void FilterControlType ( EItemType type , bool bShow ) ; <nl> + void FilterControlType ( EItemType const type , bool const bShow ) ; <nl> void CheckErrorMask ( ) ; <nl> void UpdateAudioSystemData ( ) ; <nl> void BackupTreeViewStates ( ) ; <nl> private slots : <nl> QAction * m_pSaveAction ; <nl> std : : unique_ptr < CFileMonitorSystem > m_pMonitorSystem ; <nl> std : : unique_ptr < CFileMonitorMiddleware > m_pMonitorMiddleware ; <nl> - bool m_allowedTypes [ EItemType : : eItemType_NumTypes ] ; <nl> + bool m_allowedTypes [ static_cast < int > ( EItemType : : NumTypes ) ] ; / / Replace this . Possibly with a QList . <nl> } ; <nl> } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsLoader . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsLoader . cpp <nl> <nl> <nl> # include " StdAfx . h " <nl> # include " AudioControlsLoader . h " <nl> + <nl> + # include " AudioAssetsManager . h " <nl> + # include " SystemControlsModel . h " <nl> + # include " AudioControlsEditorPlugin . h " <nl> + <nl> # include < CryAudio / IAudioSystem . h > <nl> # include < CryString / StringUtils . h > <nl> # include < CrySystem / File / CryFile . h > <nl> # include < CrySystem / ISystem . h > <nl> - # include " AudioAssetsManager . h " <nl> # include < CryString / CryPath . h > <nl> # include < IAudioSystemEditor . h > <nl> # include < IAudioSystemItem . h > <nl> - # include " QtUtil . h " <nl> - # include " IUndoObject . h " <nl> - # include " SystemControlsModel . h " <nl> - # include " IEditor . h " <nl> + # include < QtUtil . h > <nl> + # include < IUndoObject . h > <nl> + # include < IEditor . h > <nl> # include < ConfigurationManager . h > <nl> - # include " AudioControlsEditorPlugin . h " <nl> <nl> # include < QRegularExpression > <nl> <nl> EItemType TagToType ( string const & tag ) <nl> { <nl> if ( tag = = " ATLSwitch " ) <nl> { <nl> - return eItemType_Switch ; <nl> + return EItemType : : Switch ; <nl> } <nl> else if ( tag = = " ATLSwitchState " ) <nl> { <nl> - return eItemType_State ; <nl> + return EItemType : : State ; <nl> } <nl> else if ( tag = = " ATLEnvironment " ) <nl> { <nl> - return eItemType_Environment ; <nl> + return EItemType : : Environment ; <nl> } <nl> else if ( tag = = " ATLRtpc " ) <nl> { <nl> - return eItemType_Parameter ; <nl> + return EItemType : : Parameter ; <nl> } <nl> else if ( tag = = " ATLTrigger " ) <nl> { <nl> - return eItemType_Trigger ; <nl> + return EItemType : : Trigger ; <nl> } <nl> else if ( tag = = " ATLPreloadRequest " ) <nl> { <nl> - return eItemType_Preload ; <nl> + return EItemType : : Preload ; <nl> } <nl> - return eItemType_NumTypes ; <nl> + return EItemType : : NumTypes ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CAudioControlsLoader : : CAudioControlsLoader ( CAudioAssetsManager * pAssetsManager ) <nl> : m_pAssetsManager ( pAssetsManager ) <nl> - , m_errorCodeMask ( EErrorCode : : eErrorCode_NoError ) <nl> + , m_errorCodeMask ( EErrorCode : : NoError ) <nl> { } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CAudioControl * CAudioControlsLoader : : LoadControl ( XmlNodeRef pNode , Scope scope , <nl> { <nl> switch ( controlType ) <nl> { <nl> - case eItemType_Trigger : <nl> + case EItemType : : Trigger : <nl> { <nl> float radius = 0 . 0f ; <nl> pNode - > getAttr ( " atl_radius " , radius ) ; <nl> CAudioControl * CAudioControlsLoader : : LoadControl ( XmlNodeRef pNode , Scope scope , <nl> LoadConnections ( pNode , pControl ) ; <nl> } <nl> break ; <nl> - case eItemType_Switch : <nl> + case EItemType : : Switch : <nl> { <nl> int const stateCount = pNode - > getChildCount ( ) ; <nl> for ( int i = 0 ; i < stateCount ; + + i ) <nl> CAudioControl * CAudioControlsLoader : : LoadControl ( XmlNodeRef pNode , Scope scope , <nl> } <nl> } <nl> break ; <nl> - case eItemType_Preload : <nl> + case EItemType : : Preload : <nl> LoadPreloadConnections ( pNode , pControl , version ) ; <nl> break ; <nl> default : <nl> void CAudioControlsLoader : : CreateDefaultControls ( ) <nl> <nl> if ( pLibrary ! = nullptr ) <nl> { <nl> - CAudioControl * pControl = m_pAssetsManager - > FindControl ( CryAudio : : GetFocusTriggerName , eItemType_Trigger ) ; <nl> + CAudioControl * pControl = m_pAssetsManager - > FindControl ( CryAudio : : GetFocusTriggerName , EItemType : : Trigger ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - m_pAssetsManager - > CreateControl ( CryAudio : : GetFocusTriggerName , eItemType_Trigger , pLibrary ) ; <nl> + m_pAssetsManager - > CreateControl ( CryAudio : : GetFocusTriggerName , EItemType : : Trigger , pLibrary ) ; <nl> bWasModified = true ; <nl> } <nl> <nl> - pControl = m_pAssetsManager - > FindControl ( CryAudio : : LoseFocusTriggerName , eItemType_Trigger ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( CryAudio : : LoseFocusTriggerName , EItemType : : Trigger ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - m_pAssetsManager - > CreateControl ( CryAudio : : LoseFocusTriggerName , eItemType_Trigger , pLibrary ) ; <nl> + m_pAssetsManager - > CreateControl ( CryAudio : : LoseFocusTriggerName , EItemType : : Trigger , pLibrary ) ; <nl> bWasModified = true ; <nl> } <nl> <nl> - pControl = m_pAssetsManager - > FindControl ( CryAudio : : MuteAllTriggerName , eItemType_Trigger ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( CryAudio : : MuteAllTriggerName , EItemType : : Trigger ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - m_pAssetsManager - > CreateControl ( CryAudio : : MuteAllTriggerName , eItemType_Trigger , pLibrary ) ; <nl> + m_pAssetsManager - > CreateControl ( CryAudio : : MuteAllTriggerName , EItemType : : Trigger , pLibrary ) ; <nl> bWasModified = true ; <nl> } <nl> <nl> - pControl = m_pAssetsManager - > FindControl ( CryAudio : : UnmuteAllTriggerName , eItemType_Trigger ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( CryAudio : : UnmuteAllTriggerName , EItemType : : Trigger ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - m_pAssetsManager - > CreateControl ( CryAudio : : UnmuteAllTriggerName , eItemType_Trigger , pLibrary ) ; <nl> + m_pAssetsManager - > CreateControl ( CryAudio : : UnmuteAllTriggerName , EItemType : : Trigger , pLibrary ) ; <nl> bWasModified = true ; <nl> } <nl> <nl> - pControl = m_pAssetsManager - > FindControl ( CryAudio : : DoNothingTriggerName , eItemType_Trigger ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( CryAudio : : DoNothingTriggerName , EItemType : : Trigger ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - m_pAssetsManager - > CreateControl ( CryAudio : : DoNothingTriggerName , eItemType_Trigger , pLibrary ) ; <nl> + m_pAssetsManager - > CreateControl ( CryAudio : : DoNothingTriggerName , EItemType : : Trigger , pLibrary ) ; <nl> bWasModified = true ; <nl> } <nl> <nl> void CAudioControlsLoader : : CreateDefaultControls ( ) <nl> are handled for backwards compatibility reasons . <nl> Introduced in March 2017 , remove this code at a feasible point in the future . <nl> * / <nl> - pControl = m_pAssetsManager - > FindControl ( CryAudio : : AbsoluteVelocityParameterName , eItemType_Parameter ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( CryAudio : : AbsoluteVelocityParameterName , EItemType : : Parameter ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - pControl = m_pAssetsManager - > FindControl ( " object_speed " , eItemType_Parameter ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( " object_speed " , EItemType : : Parameter ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - m_pAssetsManager - > CreateControl ( CryAudio : : AbsoluteVelocityParameterName , eItemType_Parameter , pLibrary ) ; <nl> + m_pAssetsManager - > CreateControl ( CryAudio : : AbsoluteVelocityParameterName , EItemType : : Parameter , pLibrary ) ; <nl> } <nl> else <nl> { <nl> void CAudioControlsLoader : : CreateDefaultControls ( ) <nl> bWasModified = true ; <nl> } <nl> <nl> - pControl = m_pAssetsManager - > FindControl ( CryAudio : : RelativeVelocityParameterName , eItemType_Parameter ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( CryAudio : : RelativeVelocityParameterName , EItemType : : Parameter ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - pControl = m_pAssetsManager - > FindControl ( " object_doppler " , eItemType_Parameter ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( " object_doppler " , EItemType : : Parameter ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - m_pAssetsManager - > CreateControl ( CryAudio : : RelativeVelocityParameterName , eItemType_Parameter , pLibrary ) ; <nl> + m_pAssetsManager - > CreateControl ( CryAudio : : RelativeVelocityParameterName , EItemType : : Parameter , pLibrary ) ; <nl> } <nl> else <nl> { <nl> void CAudioControlsLoader : : CreateDefaultControls ( ) <nl> char const * const arr [ ] = { CryAudio : : OnStateName , CryAudio : : OffStateName } ; <nl> SwitchStates const states ( arr , arr + sizeof ( arr ) / sizeof ( arr [ 0 ] ) ) ; <nl> <nl> - pControl = m_pAssetsManager - > FindControl ( CryAudio : : AbsoluteVelocityTrackingSwitchName , eItemType_Switch ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( CryAudio : : AbsoluteVelocityTrackingSwitchName , EItemType : : Switch ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - pControl = m_pAssetsManager - > FindControl ( " object_velocity_tracking " , eItemType_Switch ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( " object_velocity_tracking " , EItemType : : Switch ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> void CAudioControlsLoader : : CreateDefaultControls ( ) <nl> bWasModified = true ; <nl> } <nl> <nl> - pControl = m_pAssetsManager - > FindControl ( CryAudio : : RelativeVelocityTrackingSwitchName , eItemType_Switch ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( CryAudio : : RelativeVelocityTrackingSwitchName , EItemType : : Switch ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> - pControl = m_pAssetsManager - > FindControl ( " object_doppler_tracking " , eItemType_Switch ) ; <nl> + pControl = m_pAssetsManager - > FindControl ( " object_doppler_tracking " , EItemType : : Switch ) ; <nl> <nl> if ( pControl = = nullptr ) <nl> { <nl> void CAudioControlsLoader : : CreateDefaultControls ( ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsLoader : : CreateDefaultSwitch ( CAudioAsset * pLibrary , const char * szExternalName , const char * szInternalName , SwitchStates const & states ) <nl> { <nl> - CAudioControl * pSwitch = m_pAssetsManager - > FindControl ( szExternalName , eItemType_Switch ) ; <nl> + CAudioControl * pSwitch = m_pAssetsManager - > FindControl ( szExternalName , EItemType : : Switch ) ; <nl> <nl> if ( pSwitch ) <nl> { <nl> void CAudioControlsLoader : : CreateDefaultSwitch ( CAudioAsset * pLibrary , const char <nl> } <nl> else <nl> { <nl> - pSwitch = m_pAssetsManager - > CreateControl ( szExternalName , eItemType_Switch , pLibrary ) ; <nl> + pSwitch = m_pAssetsManager - > CreateControl ( szExternalName , EItemType : : Switch , pLibrary ) ; <nl> } <nl> <nl> for ( auto const & szStateName : states ) <nl> void CAudioControlsLoader : : CreateDefaultSwitch ( CAudioAsset * pLibrary , const char <nl> for ( size_t i = 0 ; i < stateCount ; + + i ) <nl> { <nl> CAudioControl * pChild = static_cast < CAudioControl * > ( pSwitch - > GetChild ( i ) ) ; <nl> - if ( pChild & & ( strcmp ( pChild - > GetName ( ) . c_str ( ) , szStateName ) = = 0 ) & & pChild - > GetType ( ) = = eItemType_State ) <nl> + if ( pChild & & ( strcmp ( pChild - > GetName ( ) . c_str ( ) , szStateName ) = = 0 ) & & pChild - > GetType ( ) = = EItemType : : State ) <nl> { <nl> pState = pChild ; <nl> break ; <nl> void CAudioControlsLoader : : CreateDefaultSwitch ( CAudioAsset * pLibrary , const char <nl> <nl> if ( pState = = nullptr ) <nl> { <nl> - pState = m_pAssetsManager - > CreateControl ( szStateName , eItemType_State , pSwitch ) ; <nl> + pState = m_pAssetsManager - > CreateControl ( szStateName , EItemType : : State , pSwitch ) ; <nl> <nl> XmlNodeRef pRequestNode = GetISystem ( ) - > CreateXmlNode ( " ATLSwitchRequest " ) ; <nl> pRequestNode - > setAttr ( " atl_name " , szInternalName ) ; <nl> void CAudioControlsLoader : : LoadConnections ( XmlNodeRef pRoot , CAudioControl * pCon <nl> <nl> if ( radius ! = pControl - > GetRadius ( ) ) <nl> { <nl> - m_errorCodeMask | = eErrorCode_NonMatchedActivityRadius ; <nl> + m_errorCodeMask | = EErrorCode : : NonMatchedActivityRadius ; <nl> pControl - > SetModified ( true , true ) ; <nl> } <nl> } <nl> void CAudioControlsLoader : : LoadPreloadConnections ( XmlNodeRef pNode , CAudioContro <nl> <nl> if ( platformIndex = = - 1 ) <nl> { <nl> - m_errorCodeMask | = static_cast < uint > ( EErrorCode : : eErrorCode_UnkownPlatform ) ; <nl> + m_errorCodeMask | = EErrorCode : : UnkownPlatform ; <nl> pControl - > SetModified ( true , true ) ; <nl> } <nl> <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsLoader . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsLoader . h <nl> <nl> <nl> # pragma once <nl> <nl> - # include < CryString / CryString . h > <nl> - # include < IAudioConnection . h > <nl> # include " AudioAssets . h " <nl> - # include < CrySystem / XML / IXml . h > <nl> - # include < ACETypes . h > <nl> <nl> namespace ACE <nl> { <nl> class CAudioAssetsManager ; <nl> class CAudioControlsLoader <nl> { <nl> public : <nl> + <nl> CAudioControlsLoader ( CAudioAssetsManager * pAssetsManager ) ; <nl> std : : set < string > GetLoadedFilenamesList ( ) ; <nl> void LoadAll ( ) ; <nl> void LoadControls ( ) ; <nl> void LoadScopes ( ) ; <nl> - uint GetErrorCodeMask ( ) const { return m_errorCodeMask ; } <nl> + EErrorCode GetErrorCodeMask ( ) const { return m_errorCodeMask ; } <nl> <nl> private : <nl> + <nl> using SwitchStates = std : : vector < const char * > ; <nl> + <nl> void LoadAllLibrariesInFolder ( string const & folderPath , string const & level ) ; <nl> void LoadControlsLibrary ( XmlNodeRef pRoot , string const & filepath , string const & level , string const & filename , uint version ) ; <nl> CAudioControl * LoadControl ( XmlNodeRef pNode , Scope scope , uint version , CAudioAsset * pParentItem ) ; <nl> class CAudioControlsLoader <nl> <nl> CAudioAssetsManager * m_pAssetsManager ; <nl> std : : set < string > m_loadedFilenames ; <nl> - uint m_errorCodeMask ; <nl> + EErrorCode m_errorCodeMask ; <nl> } ; <nl> - } <nl> + } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsWriter . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsWriter . cpp <nl> <nl> <nl> # include " StdAfx . h " <nl> # include " AudioControlsWriter . h " <nl> + <nl> + # include " AudioAssetsManager . h " <nl> + <nl> + # include < IAudioSystemEditor . h > <nl> + # include < IAudioSystemItem . h > <nl> # include < CryString / StringUtils . h > <nl> # include < CrySystem / File / CryFile . h > <nl> # include < CrySystem / ISystem . h > <nl> - # include " AudioAssetsManager . h " <nl> # include < ISourceControl . h > <nl> # include < IEditor . h > <nl> - # include < IAudioSystemEditor . h > <nl> - # include < IAudioSystemItem . h > <nl> - # include " QtUtil . h " <nl> + # include < QtUtil . h > <nl> # include < ConfigurationManager . h > <nl> - # include < QModelIndex > <nl> <nl> using namespace PathUtil ; <nl> <nl> namespace ACE <nl> { <nl> + string const CAudioControlsWriter : : s_controlsPath = AUDIO_SYSTEM_DATA_ROOT CRY_NATIVE_PATH_SEPSTR " ace " CRY_NATIVE_PATH_SEPSTR ; <nl> + string const CAudioControlsWriter : : s_levelsFolder = " levels " CRY_NATIVE_PATH_SEPSTR ; <nl> + uint const CAudioControlsWriter : : s_currentFileVersion = 2 ; <nl> <nl> - const string CAudioControlsWriter : : ms_controlsPath = AUDIO_SYSTEM_DATA_ROOT CRY_NATIVE_PATH_SEPSTR " ace " CRY_NATIVE_PATH_SEPSTR ; <nl> - const string CAudioControlsWriter : : ms_levelsFolder = " levels " CRY_NATIVE_PATH_SEPSTR ; <nl> - const uint CAudioControlsWriter : : ms_currentFileVersion = 2 ; <nl> - <nl> - string TypeToTag ( EItemType eType ) <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + string TypeToTag ( EItemType const eType ) <nl> { <nl> switch ( eType ) <nl> { <nl> - case eItemType_Parameter : <nl> + case EItemType : : Parameter : <nl> return " ATLRtpc " ; <nl> - case eItemType_Trigger : <nl> + case EItemType : : Trigger : <nl> return " ATLTrigger " ; <nl> - case eItemType_Switch : <nl> + case EItemType : : Switch : <nl> return " ATLSwitch " ; <nl> - case eItemType_State : <nl> + case EItemType : : State : <nl> return " ATLSwitchState " ; <nl> - case eItemType_Preload : <nl> + case EItemType : : Preload : <nl> return " ATLPreloadRequest " ; <nl> - case eItemType_Environment : <nl> + case EItemType : : Environment : <nl> return " ATLEnvironment " ; <nl> } <nl> return " " ; <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CAudioControlsWriter : : CAudioControlsWriter ( CAudioAssetsManager * pAssetsManager , IAudioSystemEditor * pAudioSystemImpl , std : : set < string > & previousLibraryPaths ) <nl> : m_pAssetsManager ( pAssetsManager ) <nl> , m_pAudioSystemImpl ( pAudioSystemImpl ) <nl> { <nl> if ( pAssetsManager & & pAudioSystemImpl ) <nl> { <nl> - const size_t libCount = pAssetsManager - > GetLibraryCount ( ) ; <nl> + size_t const libCount = pAssetsManager - > GetLibraryCount ( ) ; <nl> + <nl> for ( size_t i = 0 ; i < libCount ; + + i ) <nl> { <nl> CAudioLibrary & library = * pAssetsManager - > GetLibrary ( i ) ; <nl> CAudioControlsWriter : : CAudioControlsWriter ( CAudioAssetsManager * pAssetsManager , <nl> } <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsWriter : : WriteLibrary ( CAudioLibrary & library ) <nl> { <nl> if ( library . IsModified ( ) ) <nl> { <nl> LibraryStorage libraryXmlNodes ; <nl> <nl> - const size_t itemCount = library . ChildCount ( ) ; <nl> + size_t const itemCount = library . ChildCount ( ) ; <nl> + <nl> for ( size_t i = 0 ; i < itemCount ; + + i ) <nl> { <nl> WriteItem ( library . GetChild ( i ) , " " , libraryXmlNodes ) ; <nl> void CAudioControlsWriter : : WriteLibrary ( CAudioLibrary & library ) <nl> <nl> for ( auto const & libraryPair : libraryXmlNodes ) <nl> { <nl> - string libraryPath = ms_controlsPath ; <nl> - const Scope scope = libraryPair . first ; <nl> + string libraryPath = s_controlsPath ; <nl> + Scope const scope = libraryPair . first ; <nl> + <nl> if ( scope = = Utils : : GetGlobalScope ( ) ) <nl> { <nl> / / no scope , file at the root level <nl> void CAudioControlsWriter : : WriteLibrary ( CAudioLibrary & library ) <nl> else <nl> { <nl> / / with scope , inside level folder <nl> - libraryPath + = ms_levelsFolder + m_pAssetsManager - > GetScopeInfo ( scope ) . name + CRY_NATIVE_PATH_SEPSTR + library . GetName ( ) ; <nl> + libraryPath + = s_levelsFolder + m_pAssetsManager - > GetScopeInfo ( scope ) . name + CRY_NATIVE_PATH_SEPSTR + library . GetName ( ) ; <nl> } <nl> <nl> m_foundLibraryPaths . insert ( libraryPath . MakeLower ( ) + " . xml " ) ; <nl> <nl> - const SLibraryScope & libScope = libraryPair . second ; <nl> + SLibraryScope const & libScope = libraryPair . second ; <nl> + <nl> if ( libScope . bDirty ) <nl> { <nl> XmlNodeRef pFileNode = GetISystem ( ) - > CreateXmlNode ( " ATLConfig " ) ; <nl> pFileNode - > setAttr ( " atl_name " , library . GetName ( ) ) ; <nl> - pFileNode - > setAttr ( " atl_version " , ms_currentFileVersion ) ; <nl> + pFileNode - > setAttr ( " atl_version " , s_currentFileVersion ) ; <nl> + int const numTypes = static_cast < int > ( EItemType : : NumTypes ) ; <nl> <nl> - for ( int i = 0 ; i < eItemType_NumTypes ; + + i ) <nl> + for ( int i = 0 ; i < numTypes ; + + i ) <nl> { <nl> - if ( i ! = eItemType_State ) / / switch_states are written inside the switches <nl> + if ( i ! = static_cast < int > ( EItemType : : State ) ) / / switch_states are written inside the switches <nl> { <nl> XmlNodeRef node = libScope . GetXmlNode ( ( EItemType ) i ) ; <nl> + <nl> if ( node & & node - > getChildCount ( ) > 0 ) <nl> { <nl> pFileNode - > addChild ( node ) ; <nl> void CAudioControlsWriter : : WriteLibrary ( CAudioLibrary & library ) <nl> if ( pEditorData ) <nl> { <nl> XmlNodeRef pFoldersNode = pEditorData - > createNode ( " Folders " ) ; <nl> + <nl> if ( pFoldersNode ) <nl> { <nl> WriteEditorData ( & library , pFoldersNode ) ; <nl> pEditorData - > addChild ( pFoldersNode ) ; <nl> } <nl> + <nl> pFileNode - > addChild ( pEditorData ) ; <nl> } <nl> <nl> - const string fullFilePath = PathUtil : : GetGameFolder ( ) + CRY_NATIVE_PATH_SEPSTR + libraryPath + " . xml " ; <nl> + string const fullFilePath = PathUtil : : GetGameFolder ( ) + CRY_NATIVE_PATH_SEPSTR + libraryPath + " . xml " ; <nl> + <nl> + DWORD const fileAttributes = GetFileAttributesA ( fullFilePath . c_str ( ) ) ; <nl> <nl> - const DWORD fileAttributes = GetFileAttributesA ( fullFilePath . c_str ( ) ) ; <nl> if ( fileAttributes & FILE_ATTRIBUTE_READONLY ) <nl> { <nl> / / file is read - only <nl> void CAudioControlsWriter : : WriteLibrary ( CAudioLibrary & library ) <nl> { <nl> std : : unordered_set < Scope > scopes ; <nl> <nl> - const size_t numChildren = library . ChildCount ( ) ; <nl> + size_t const numChildren = library . ChildCount ( ) ; <nl> <nl> for ( size_t i = 0 ; i < numChildren ; + + i ) <nl> { <nl> void CAudioControlsWriter : : WriteLibrary ( CAudioLibrary & library ) <nl> <nl> for ( auto const scope : scopes ) <nl> { <nl> - string libraryPath = ms_controlsPath ; <nl> + string libraryPath = s_controlsPath ; <nl> <nl> if ( scope = = Utils : : GetGlobalScope ( ) ) <nl> { <nl> void CAudioControlsWriter : : WriteLibrary ( CAudioLibrary & library ) <nl> else <nl> { <nl> / / with scope , inside level folder <nl> - libraryPath + = ms_levelsFolder + m_pAssetsManager - > GetScopeInfo ( scope ) . name + CRY_NATIVE_PATH_SEPSTR + library . GetName ( ) ; <nl> + libraryPath + = s_levelsFolder + m_pAssetsManager - > GetScopeInfo ( scope ) . name + CRY_NATIVE_PATH_SEPSTR + library . GetName ( ) ; <nl> } <nl> <nl> m_foundLibraryPaths . insert ( libraryPath . MakeLower ( ) + " . xml " ) ; <nl> void CAudioControlsWriter : : WriteLibrary ( CAudioLibrary & library ) <nl> } <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsWriter : : WriteItem ( CAudioAsset * pItem , const string & path , LibraryStorage & library ) <nl> { <nl> if ( pItem ) <nl> { <nl> - if ( pItem - > GetType ( ) = = EItemType : : eItemType_Folder ) <nl> + if ( pItem - > GetType ( ) = = EItemType : : Folder ) <nl> { <nl> - const size_t itemCount = pItem - > ChildCount ( ) ; <nl> + size_t const itemCount = pItem - > ChildCount ( ) ; <nl> + <nl> for ( size_t i = 0 ; i < itemCount ; + + i ) <nl> { <nl> / / Use forward slash only to ensure cross platform compatibility . <nl> void CAudioControlsWriter : : WriteItem ( CAudioAsset * pItem , const string & path , Lib <nl> else <nl> { <nl> CAudioControl * pControl = static_cast < CAudioControl * > ( pItem ) ; <nl> + <nl> if ( pControl ) <nl> { <nl> SLibraryScope & scope = library [ pControl - > GetScope ( ) ] ; <nl> void CAudioControlsWriter : : WriteItem ( CAudioAsset * pItem , const string & path , Lib <nl> WriteControlToXML ( scope . GetXmlNode ( pControl - > GetType ( ) ) , pControl , path ) ; <nl> } <nl> } <nl> + <nl> + pItem - > SetModified ( false ) ; <nl> } <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsWriter : : GetScopes ( CAudioAsset const * const pItem , std : : unordered_set < Scope > & scopes ) <nl> { <nl> - if ( pItem - > GetType ( ) = = EItemType : : eItemType_Folder ) <nl> + if ( pItem - > GetType ( ) = = EItemType : : Folder ) <nl> { <nl> size_t const numChildren = pItem - > ChildCount ( ) ; <nl> <nl> void CAudioControlsWriter : : GetScopes ( CAudioAsset const * const pItem , std : : unorde <nl> } <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsWriter : : WriteControlToXML ( XmlNodeRef pNode , CAudioControl * pControl , const string & path ) <nl> { <nl> - const EItemType type = pControl - > GetType ( ) ; <nl> + EItemType const type = pControl - > GetType ( ) ; <nl> XmlNodeRef pChildNode = pNode - > createNode ( TypeToTag ( type ) ) ; <nl> pChildNode - > setAttr ( " atl_name " , pControl - > GetName ( ) ) ; <nl> + <nl> if ( ! path . empty ( ) ) <nl> { <nl> pChildNode - > setAttr ( " path " , path ) ; <nl> } <nl> <nl> - if ( type = = eItemType_Trigger ) <nl> + if ( type = = EItemType : : Trigger ) <nl> { <nl> - const float radius = pControl - > GetRadius ( ) ; <nl> + float const radius = pControl - > GetRadius ( ) ; <nl> + <nl> if ( radius > 0 . 0f ) <nl> { <nl> pChildNode - > setAttr ( " atl_radius " , radius ) ; <nl> - const float fadeOutDistance = pControl - > GetOcclusionFadeOutDistance ( ) ; <nl> + float const fadeOutDistance = pControl - > GetOcclusionFadeOutDistance ( ) ; <nl> + <nl> if ( fadeOutDistance > 0 . 0f ) <nl> { <nl> pChildNode - > setAttr ( " atl_occlusion_fadeout_distance " , fadeOutDistance ) ; <nl> void CAudioControlsWriter : : WriteControlToXML ( XmlNodeRef pNode , CAudioControl * pC <nl> <nl> } <nl> <nl> - if ( type = = eItemType_Switch ) <nl> + if ( type = = EItemType : : Switch ) <nl> { <nl> - const size_t size = pControl - > ChildCount ( ) ; <nl> + size_t const size = pControl - > ChildCount ( ) ; <nl> + <nl> for ( size_t i = 0 ; i < size ; + + i ) <nl> { <nl> CAudioAsset * pItem = pControl - > GetChild ( i ) ; <nl> - if ( pItem & & pItem - > GetType ( ) = = EItemType : : eItemType_State ) <nl> + <nl> + if ( pItem & & pItem - > GetType ( ) = = EItemType : : State ) <nl> { <nl> WriteControlToXML ( pChildNode , static_cast < CAudioControl * > ( pItem ) , " " ) ; <nl> } <nl> } <nl> } <nl> - else if ( type = = eItemType_Preload ) <nl> + else if ( type = = EItemType : : Preload ) <nl> { <nl> if ( pControl - > IsAutoLoad ( ) ) <nl> { <nl> pChildNode - > setAttr ( " atl_type " , " AutoLoad " ) ; <nl> } <nl> <nl> - const std : : vector < dll_string > & platforms = GetIEditor ( ) - > GetConfigurationManager ( ) - > GetPlatformNames ( ) ; <nl> - const size_t count = platforms . size ( ) ; <nl> + std : : vector < dll_string > const & platforms = GetIEditor ( ) - > GetConfigurationManager ( ) - > GetPlatformNames ( ) ; <nl> + size_t const count = platforms . size ( ) ; <nl> + <nl> for ( size_t i = 0 ; i < count ; + + i ) <nl> { <nl> XmlNodeRef pGroupNode = pChildNode - > createNode ( " ATLPlatform " ) ; <nl> pGroupNode - > setAttr ( " atl_name " , platforms [ i ] . c_str ( ) ) ; <nl> WriteConnectionsToXML ( pGroupNode , pControl , i ) ; <nl> + <nl> if ( pGroupNode - > getChildCount ( ) > 0 ) <nl> { <nl> pChildNode - > addChild ( pGroupNode ) ; <nl> void CAudioControlsWriter : : WriteControlToXML ( XmlNodeRef pNode , CAudioControl * pC <nl> pNode - > addChild ( pChildNode ) ; <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsWriter : : WriteConnectionsToXML ( XmlNodeRef pNode , CAudioControl * pControl , const int platformIndex ) <nl> { <nl> if ( pControl & & m_pAudioSystemImpl ) <nl> void CAudioControlsWriter : : WriteConnectionsToXML ( XmlNodeRef pNode , CAudioControl <nl> } <nl> } <nl> <nl> - const int size = pControl - > GetConnectionCount ( ) ; <nl> + int const size = pControl - > GetConnectionCount ( ) ; <nl> + <nl> for ( int i = 0 ; i < size ; + + i ) <nl> { <nl> ConnectionPtr pConnection = pControl - > GetConnectionAt ( i ) ; <nl> + <nl> if ( pConnection ) <nl> { <nl> - if ( pControl - > GetType ( ) ! = eItemType_Preload | | pConnection - > IsPlatformEnabled ( platformIndex ) ) <nl> + if ( pControl - > GetType ( ) ! = EItemType : : Preload | | pConnection - > IsPlatformEnabled ( platformIndex ) ) <nl> { <nl> XmlNodeRef pChild = m_pAudioSystemImpl - > CreateXMLNodeFromConnection ( pConnection , pControl - > GetType ( ) ) ; <nl> + <nl> if ( pChild ) <nl> { <nl> pNode - > addChild ( pChild ) ; <nl> void CAudioControlsWriter : : WriteConnectionsToXML ( XmlNodeRef pNode , CAudioControl <nl> } <nl> } <nl> <nl> - void CAudioControlsWriter : : CheckOutFile ( const string & filepath ) <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + void CAudioControlsWriter : : CheckOutFile ( string const & filepath ) <nl> { <nl> ISourceControl * pSourceControl = GetIEditor ( ) - > GetSourceControl ( ) ; <nl> + <nl> if ( pSourceControl ) <nl> { <nl> - uint32 fileAttributes = pSourceControl - > GetFileAttributes ( filepath . c_str ( ) ) ; <nl> + uint32 const fileAttributes = pSourceControl - > GetFileAttributes ( filepath . c_str ( ) ) ; <nl> + <nl> if ( fileAttributes & SCC_FILE_ATTRIBUTE_MANAGED ) <nl> { <nl> pSourceControl - > CheckOut ( filepath ) ; <nl> void CAudioControlsWriter : : CheckOutFile ( const string & filepath ) <nl> } <nl> } <nl> <nl> - void CAudioControlsWriter : : DeleteLibraryFile ( const string & filepath ) <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + void CAudioControlsWriter : : DeleteLibraryFile ( string const & filepath ) <nl> { <nl> ISourceControl * pSourceControl = GetIEditor ( ) - > GetSourceControl ( ) ; <nl> + <nl> if ( pSourceControl & & pSourceControl - > GetFileAttributes ( filepath . c_str ( ) ) & SCC_FILE_ATTRIBUTE_MANAGED ) <nl> { <nl> / / if source control is connected , let it handle the delete <nl> void CAudioControlsWriter : : DeleteLibraryFile ( const string & filepath ) <nl> } <nl> else <nl> { <nl> - DWORD fileAttributes = GetFileAttributesA ( filepath . c_str ( ) ) ; <nl> + DWORD const fileAttributes = GetFileAttributesA ( filepath . c_str ( ) ) ; <nl> + <nl> if ( fileAttributes = = INVALID_FILE_ATTRIBUTES | | ! DeleteFile ( filepath . c_str ( ) ) ) <nl> { <nl> CryWarning ( VALIDATOR_MODULE_EDITOR , VALIDATOR_ERROR , " [ Audio Controls Editor ] Failed to delete file % s " , filepath ) ; <nl> void CAudioControlsWriter : : DeleteLibraryFile ( const string & filepath ) <nl> } <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioControlsWriter : : WriteEditorData ( CAudioAsset * pLibrary , XmlNodeRef pParentNode ) const <nl> { <nl> if ( pParentNode & & pLibrary ) <nl> { <nl> - const size_t itemCount = pLibrary - > ChildCount ( ) ; <nl> + size_t const itemCount = pLibrary - > ChildCount ( ) ; <nl> + <nl> for ( size_t i = 0 ; i < itemCount ; + + i ) <nl> { <nl> CAudioAsset * pItem = pLibrary - > GetChild ( i ) ; <nl> - if ( pItem - > GetType ( ) = = EItemType : : eItemType_Folder ) <nl> + <nl> + if ( pItem - > GetType ( ) = = EItemType : : Folder ) <nl> { <nl> XmlNodeRef pFolderNode = pParentNode - > createNode ( " Folder " ) ; <nl> + <nl> if ( pFolderNode ) <nl> { <nl> pFolderNode - > setAttr ( " name " , pItem - > GetName ( ) ) ; <nl> void CAudioControlsWriter : : WriteEditorData ( CAudioAsset * pLibrary , XmlNodeRef pPa <nl> } <nl> } <nl> } <nl> - } <nl> + } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsWriter . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioControlsWriter . h <nl> <nl> <nl> # pragma once <nl> <nl> - # include < CryString / CryString . h > <nl> - # include < IAudioConnection . h > <nl> # include " AudioAssets . h " <nl> + <nl> + # include < ACETypes . h > <nl> + # include < IAudioConnection . h > <nl> + # include < CryString / CryString . h > <nl> # include < CrySystem / XML / IXml . h > <nl> - # include < QModelIndex > <nl> # include < CrySystem / ISystem . h > <nl> - # include < ACETypes . h > <nl> - <nl> - class QStandardItemModel ; <nl> <nl> namespace ACE <nl> { <nl> struct SLibraryScope <nl> pNodes [ 4 ] = GetISystem ( ) - > CreateXmlNode ( " AudioPreloads " ) ; <nl> } <nl> <nl> - XmlNodeRef GetXmlNode ( const EItemType type ) const <nl> + XmlNodeRef GetXmlNode ( EItemType const type ) const <nl> { <nl> switch ( type ) <nl> { <nl> - case EItemType : : eItemType_Trigger : <nl> + case EItemType : : Trigger : <nl> return pNodes [ 0 ] ; <nl> - case EItemType : : eItemType_Parameter : <nl> + case EItemType : : Parameter : <nl> return pNodes [ 1 ] ; <nl> - case EItemType : : eItemType_Switch : <nl> + case EItemType : : Switch : <nl> return pNodes [ 2 ] ; <nl> - case EItemType : : eItemType_Environment : <nl> + case EItemType : : Environment : <nl> return pNodes [ 3 ] ; <nl> - case EItemType : : eItemType_Preload : <nl> + case EItemType : : Preload : <nl> return pNodes [ 4 ] ; <nl> } <nl> return nullptr ; <nl> } <nl> <nl> - XmlNodeRef pNodes [ 5 ] ; / / Trigger , RTPC , Switch , Environment , Preloads <nl> + XmlNodeRef pNodes [ 5 ] ; / / Trigger , Parameter , Switch , Environment , Preloads <nl> bool bDirty ; <nl> } ; <nl> <nl> typedef std : : map < Scope , SLibraryScope > LibraryStorage ; <nl> class CAudioControlsWriter <nl> { <nl> public : <nl> + <nl> CAudioControlsWriter ( CAudioAssetsManager * pAssetsManager , IAudioSystemEditor * pAudioSystemImpl , std : : set < string > & previousLibraryPaths ) ; <nl> <nl> private : <nl> + <nl> void WriteLibrary ( CAudioLibrary & library ) ; <nl> void WriteItem ( CAudioAsset * pItem , const string & path , LibraryStorage & library ) ; <nl> void GetScopes ( CAudioAsset const * const pItem , std : : unordered_set < Scope > & scopes ) ; <nl> class CAudioControlsWriter <nl> void WriteConnectionsToXML ( XmlNodeRef pNode , CAudioControl * pControl , const int platformIndex = - 1 ) ; <nl> void WriteEditorData ( CAudioAsset * pLibrary , XmlNodeRef pParentNode ) const ; <nl> <nl> - void CheckOutFile ( const string & filepath ) ; <nl> - void DeleteLibraryFile ( const string & filepath ) ; <nl> + void CheckOutFile ( string const & filepath ) ; <nl> + void DeleteLibraryFile ( string const & filepath ) ; <nl> <nl> CAudioAssetsManager * m_pAssetsManager ; <nl> IAudioSystemEditor * m_pAudioSystemImpl ; <nl> <nl> std : : set < string > m_foundLibraryPaths ; <nl> <nl> - static const string ms_controlsPath ; <nl> - static const string ms_levelsFolder ; <nl> - static const uint ms_currentFileVersion ; <nl> + static string const s_controlsPath ; <nl> + static string const s_levelsFolder ; <nl> + static uint const s_currentFileVersion ; <nl> } ; <nl> - } <nl> + } / / namespace ACE <nl> similarity index 75 % <nl> rename from Code / Sandbox / Plugins / EditorAudioControlsEditor / AdvancedTreeView . cpp <nl> rename to Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioTreeView . cpp <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AdvancedTreeView . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioTreeView . cpp <nl> <nl> / / Copyright 2001 - 2016 Crytek GmbH / Crytek Group . All rights reserved . <nl> <nl> # include " StdAfx . h " <nl> - # include " AdvancedTreeView . h " <nl> + # include " AudioTreeView . h " <nl> # include < CryAudio / IAudioSystem . h > <nl> <nl> # include < QMenu > <nl> + # include < QHeaderView > <nl> <nl> namespace ACE <nl> { <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - bool CAdvancedTreeView : : IsEditing ( ) const <nl> + CAudioTreeView : : CAudioTreeView ( ) <nl> + : QAdvancedTreeView ( QAdvancedTreeView : : Behavior ( QAdvancedTreeView : : None ) ) <nl> + { <nl> + QObject : : connect ( header ( ) , & QHeaderView : : sortIndicatorChanged , [ this ] ( ) { scrollTo ( currentIndex ( ) ) ; } ) ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + bool CAudioTreeView : : IsEditing ( ) const <nl> { <nl> return state ( ) = = QAbstractItemView : : EditingState ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAdvancedTreeView : : ExpandSelection ( QModelIndexList const & indexList ) <nl> + void CAudioTreeView : : ExpandSelection ( QModelIndexList const & indexList ) <nl> { <nl> for ( auto const & index : indexList ) <nl> { <nl> void CAdvancedTreeView : : ExpandSelection ( QModelIndexList const & indexList ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAdvancedTreeView : : CollapseSelection ( QModelIndexList const & indexList ) <nl> + void CAudioTreeView : : CollapseSelection ( QModelIndexList const & indexList ) <nl> { <nl> for ( auto const & index : indexList ) <nl> { <nl> void CAdvancedTreeView : : CollapseSelection ( QModelIndexList const & indexList ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - uint32 CAdvancedTreeView : : GetItemId ( QModelIndex const & index ) const <nl> + uint32 CAudioTreeView : : GetItemId ( QModelIndex const & index ) const <nl> { <nl> if ( index . isValid ( ) ) <nl> { <nl> uint32 CAdvancedTreeView : : GetItemId ( QModelIndex const & index ) const <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAdvancedTreeView : : BackupExpanded ( ) <nl> + void CAudioTreeView : : BackupExpanded ( ) <nl> { <nl> m_expandedBackup . clear ( ) ; <nl> <nl> - for ( int i = 0 ; i < model ( ) - > rowCount ( ) ; + + i ) <nl> + int const rowCount = model ( ) - > rowCount ( ) ; <nl> + <nl> + for ( int i = 0 ; i < rowCount ; + + i ) <nl> { <nl> BackupExpandedChildren ( model ( ) - > index ( i , 0 ) ) ; <nl> } <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAdvancedTreeView : : BackupExpandedChildren ( QModelIndex const & index ) <nl> + void CAudioTreeView : : BackupExpandedChildren ( QModelIndex const & index ) <nl> { <nl> if ( index . isValid ( ) ) <nl> { <nl> void CAdvancedTreeView : : BackupExpandedChildren ( QModelIndex const & index ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAdvancedTreeView : : RestoreExpanded ( ) <nl> + void CAudioTreeView : : RestoreExpanded ( ) <nl> { <nl> if ( ! m_expandedBackup . isEmpty ( ) ) <nl> { <nl> - for ( int i = 0 ; i < model ( ) - > rowCount ( ) ; + + i ) <nl> + int const rowCount = model ( ) - > rowCount ( ) ; <nl> + for ( int i = 0 ; i < rowCount ; + + i ) <nl> { <nl> RestoreExpandedChildren ( model ( ) - > index ( i , 0 ) ) ; <nl> } <nl> void CAdvancedTreeView : : RestoreExpanded ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAdvancedTreeView : : RestoreExpandedChildren ( QModelIndex const & index ) <nl> + void CAudioTreeView : : RestoreExpandedChildren ( QModelIndex const & index ) <nl> { <nl> if ( index . isValid ( ) ) <nl> { <nl> void CAdvancedTreeView : : RestoreExpandedChildren ( QModelIndex const & index ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAdvancedTreeView : : BackupSelection ( ) <nl> + void CAudioTreeView : : BackupSelection ( ) <nl> { <nl> m_selectionBackup . clear ( ) ; <nl> m_bSelectionChanged = false ; <nl> void CAdvancedTreeView : : BackupSelection ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAdvancedTreeView : : RestoreSelection ( ) <nl> + void CAudioTreeView : : RestoreSelection ( ) <nl> { <nl> if ( ! m_selectionBackup . isEmpty ( ) & & ! m_bSelectionChanged ) <nl> { <nl> - for ( int i = 0 ; i < model ( ) - > rowCount ( ) ; + + i ) <nl> + int const rowCount = model ( ) - > rowCount ( ) ; <nl> + <nl> + for ( int i = 0 ; i < rowCount ; + + i ) <nl> { <nl> RestoreSelectionChildren ( model ( ) - > index ( i , 0 ) ) ; <nl> } <nl> void CAdvancedTreeView : : RestoreSelection ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAdvancedTreeView : : RestoreSelectionChildren ( QModelIndex const & index ) <nl> + void CAudioTreeView : : RestoreSelectionChildren ( QModelIndex const & index ) <nl> { <nl> if ( index . isValid ( ) ) <nl> { <nl> void CAdvancedTreeView : : RestoreSelectionChildren ( QModelIndex const & index ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CAdvancedTreeView : : OnSelectionChanged ( QItemSelection const & selected , QItemSelection const & deselected ) <nl> + void CAudioTreeView : : OnSelectionChanged ( QItemSelection const & selected , QItemSelection const & deselected ) <nl> { <nl> for ( QModelIndex const & index : selected . indexes ( ) ) <nl> { <nl> similarity index 86 % <nl> rename from Code / Sandbox / Plugins / EditorAudioControlsEditor / AdvancedTreeView . h <nl> rename to Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioTreeView . h <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / AdvancedTreeView . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / AudioTreeView . h <nl> <nl> <nl> namespace ACE <nl> { <nl> - class CAdvancedTreeView final : public QAdvancedTreeView <nl> + class CAudioTreeView final : public QAdvancedTreeView <nl> { <nl> Q_OBJECT <nl> <nl> public : <nl> <nl> - CAdvancedTreeView ( ) <nl> - : QAdvancedTreeView ( QAdvancedTreeView : : Behavior ( QAdvancedTreeView : : None ) ) <nl> - { } <nl> + CAudioTreeView ( ) ; <nl> <nl> QModelIndexList GetSelectedIndexes ( ) const { return selectedIndexes ( ) ; } <nl> bool IsEditing ( ) const ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / CMakeLists . txt <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / CMakeLists . txt <nl> add_sources ( " EditorAudioControlsEditor_uber_0 . cpp " <nl> " ImplementationManager . h " <nl> " ImplementationManager . cpp " <nl> " SystemControlsEditorIcons . h " <nl> - " AdvancedTreeView . cpp " <nl> - " AdvancedTreeView . h " <nl> + " AudioTreeView . cpp " <nl> + " AudioTreeView . h " <nl> " FileMonitor . cpp " <nl> " FileMonitor . h " <nl> SOURCE_GROUP " SystemControls " <nl> add_sources ( " EditorAudioControlsEditor_uber_0 . cpp " <nl> SOURCE_GROUP " Properties " <nl> " PropertiesWidget . h " <nl> " PropertiesWidget . cpp " <nl> + SOURCE_GROUP " Connections " <nl> " ConnectionsWidget . h " <nl> " ConnectionsWidget . cpp " <nl> " ConnectionsModel . h " <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / ConnectionsModel . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / ConnectionsModel . cpp <nl> int CConnectionModel : : rowCount ( const QModelIndex & parent ) const <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> int CConnectionModel : : columnCount ( const QModelIndex & parent ) const <nl> { <nl> - return static_cast < int > ( eConnectionModelColumns_Size ) + static_cast < int > ( m_platformNames . size ( ) ) ; <nl> + return static_cast < int > ( EConnectionModelColumns : : Size ) + static_cast < int > ( m_platformNames . size ( ) ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> QVariant CConnectionModel : : data ( const QModelIndex & index , int role ) const <nl> case Qt : : DisplayRole : <nl> switch ( index . column ( ) ) <nl> { <nl> - case eConnectionModelColumns_Name : <nl> + case static_cast < int > ( EConnectionModelColumns : : Name ) : <nl> return ( const char * ) pItem - > GetName ( ) ; <nl> - case eConnectionModelColumns_Path : <nl> + case static_cast < int > ( EConnectionModelColumns : : Path ) : <nl> { <nl> QString path ; <nl> IAudioSystemItem * pParent = pItem - > GetParent ( ) ; <nl> QVariant CConnectionModel : : data ( const QModelIndex & index , int role ) const <nl> } <nl> break ; <nl> case Qt : : DecorationRole : <nl> - if ( index . column ( ) = = eConnectionModelColumns_Name ) <nl> + if ( index . column ( ) = = static_cast < int > ( EConnectionModelColumns : : Name ) ) <nl> { <nl> return CryIcon ( ( QtUtil : : ToQString ( PathUtil : : GetEnginePath ( ) ) + CRY_NATIVE_PATH_SEPSTR ) + m_pAudioSystem - > GetTypeIcon ( pItem - > GetType ( ) ) ) ; <nl> } <nl> QVariant CConnectionModel : : data ( const QModelIndex & index , int role ) const <nl> break ; <nl> case Qt : : CheckStateRole : <nl> { <nl> - if ( ( m_pControl - > GetType ( ) = = eItemType_Preload ) & & ( index . column ( ) > = eConnectionModelColumns_Size ) ) <nl> + if ( ( m_pControl - > GetType ( ) = = EItemType : : Preload ) & & ( index . column ( ) > = static_cast < int > ( EConnectionModelColumns : : Size ) ) ) <nl> { <nl> - return pConnection - > IsPlatformEnabled ( index . column ( ) - eConnectionModelColumns_Size ) ? Qt : : Checked : Qt : : Unchecked ; <nl> + return pConnection - > IsPlatformEnabled ( index . column ( ) - static_cast < int > ( EConnectionModelColumns : : Size ) ) ? Qt : : Checked : Qt : : Unchecked ; <nl> } <nl> break ; <nl> } <nl> - case eConnectionModelRoles_Id : <nl> - if ( index . column ( ) = = eConnectionModelColumns_Name ) <nl> + case static_cast < int > ( EConnectionModelRoles : : Id ) : <nl> + if ( index . column ( ) = = static_cast < int > ( EConnectionModelColumns : : Name ) ) <nl> { <nl> return pItem - > GetId ( ) ; <nl> } <nl> QVariant CConnectionModel : : headerData ( int section , Qt : : Orientation orientation , <nl> if ( orientation = = Qt : : Horizontal & & role = = Qt : : DisplayRole ) <nl> { <nl> <nl> - if ( section < eConnectionModelColumns_Size ) <nl> + if ( section < static_cast < int > ( EConnectionModelColumns : : Size ) ) <nl> { <nl> switch ( section ) <nl> { <nl> - case eConnectionModelColumns_Name : <nl> + case static_cast < int > ( EConnectionModelColumns : : Name ) : <nl> return tr ( " Name " ) ; <nl> - case eConnectionModelColumns_Path : <nl> + case static_cast < int > ( EConnectionModelColumns : : Path ) : <nl> return tr ( " Path " ) ; <nl> } <nl> } <nl> else <nl> { <nl> - return m_platformNames [ section - eConnectionModelColumns_Size ] ; <nl> + return m_platformNames [ section - static_cast < int > ( EConnectionModelColumns : : Size ) ] ; <nl> } <nl> } <nl> return QVariant ( ) ; <nl> QVariant CConnectionModel : : headerData ( int section , Qt : : Orientation orientation , <nl> Qt : : ItemFlags CConnectionModel : : flags ( const QModelIndex & index ) const <nl> { <nl> Qt : : ItemFlags flags = QAbstractItemModel : : flags ( index ) ; <nl> - if ( index . isValid ( ) & & index . column ( ) > = eConnectionModelColumns_Size ) <nl> + if ( index . isValid ( ) & & index . column ( ) > = static_cast < int > ( EConnectionModelColumns : : Size ) ) <nl> { <nl> flags | = Qt : : ItemIsUserCheckable ; <nl> } <nl> Qt : : ItemFlags CConnectionModel : : flags ( const QModelIndex & index ) const <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> bool CConnectionModel : : setData ( const QModelIndex & index , const QVariant & value , int role ) <nl> { <nl> - if ( index . column ( ) > = eConnectionModelColumns_Size & & role = = Qt : : CheckStateRole ) <nl> + if ( ( index . column ( ) > = static_cast < int > ( EConnectionModelColumns : : Size ) ) & & ( role = = Qt : : CheckStateRole ) ) <nl> { <nl> ConnectionPtr pConnection = m_connectionsCache [ index . row ( ) ] ; <nl> - pConnection - > EnableForPlatform ( index . column ( ) - eConnectionModelColumns_Size , value = = Qt : : Checked ) ; <nl> + pConnection - > EnableForPlatform ( index . column ( ) - static_cast < int > ( EConnectionModelColumns : : Size ) , value = = Qt : : Checked ) ; <nl> QVector < int > roleVector ( 1 , role ) ; <nl> dataChanged ( index , index , roleVector ) ; <nl> return true ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / ConnectionsModel . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / ConnectionsModel . h <nl> <nl> # include < QAbstractItemModel > <nl> # include < ACETypes . h > <nl> <nl> - class QVBoxLayout ; <nl> - class QFrame ; <nl> - class QPropertyTree ; <nl> - class QTreeView ; <nl> - <nl> namespace ACE <nl> { <nl> class CAudioControl ; <nl> class IAudioSystemEditor ; <nl> <nl> - class CConnectionModel : public QAbstractItemModel <nl> + class CConnectionModel final : public QAbstractItemModel <nl> { <nl> public : <nl> <nl> class CConnectionModel : public QAbstractItemModel <nl> <nl> void Init ( CAudioControl * pControl ) ; <nl> <nl> - enum EConnectionModelRoles <nl> + enum class EConnectionModelRoles <nl> { <nl> - eConnectionModelRoles_Id = Qt : : UserRole + 1 , <nl> + Id = Qt : : UserRole + 1 , <nl> } ; <nl> <nl> - enum EConnectionModelColumns <nl> + enum class EConnectionModelColumns <nl> { <nl> - eConnectionModelColumns_Name = 0 , <nl> - eConnectionModelColumns_Path , <nl> - eConnectionModelColumns_Size , <nl> + Name = 0 , <nl> + Path , <nl> + Size , <nl> } ; <nl> <nl> / / QAbstractTableModel <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / ConnectionsWidget . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / ConnectionsWidget . cpp <nl> <nl> <nl> # include " StdAfx . h " <nl> # include " ConnectionsWidget . h " <nl> - # include < IAudioSystemEditor . h > <nl> - # include < IAudioSystemItem . h > <nl> + <nl> # include " AudioAssets . h " <nl> # include " AudioControlsEditorPlugin . h " <nl> - # include " IEditor . h " <nl> - # include " QtUtil . h " <nl> + # include < IAudioSystemEditor . h > <nl> + # include < IAudioSystemItem . h > <nl> # include " ImplementationManager . h " <nl> # include " MiddlewareDataWidget . h " <nl> # include " MiddlewareDataModel . h " <nl> - # include " AdvancedTreeView . h " <nl> + # include " AudioTreeView . h " <nl> # include " ConnectionsModel . h " <nl> - # include " IUndoObject . h " <nl> - # include " Controls / QuestionDialog . h " <nl> <nl> + # include < IEditor . h > <nl> + # include < QtUtil . h > <nl> + # include < IUndoObject . h > <nl> + # include < Controls / QuestionDialog . h > <nl> # include < CrySerialization / IArchive . h > <nl> # include < CrySerialization / STL . h > <nl> # include < Serialization / QPropertyTree / QPropertyTree . h > <nl> + # include < ProxyModels / DeepFilterProxyModel . h > <nl> <nl> - # include < QDropEvent > <nl> - # include < QEvent > <nl> - # include < QMimeData > <nl> - # include < QMenu > <nl> - # include < QVBoxLayout > <nl> # include < QHeaderView > <nl> + # include < QKeyEvent > <nl> + # include < QMenu > <nl> # include < QSplitter > <nl> - # include < QSizePolicy > <nl> + # include < QVBoxLayout > <nl> <nl> namespace ACE <nl> { <nl> CConnectionsWidget : : CConnectionsWidget ( QWidget * pParent ) <nl> : QWidget ( pParent ) <nl> , m_pControl ( nullptr ) <nl> , m_pConnectionModel ( new CConnectionModel ( ) ) <nl> - , m_pConnectionsView ( new CAdvancedTreeView ( ) ) <nl> + , m_pTreeView ( new CAudioTreeView ( ) ) <nl> { <nl> - m_pConnectionsView - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ; <nl> - m_pConnectionsView - > setDragEnabled ( false ) ; <nl> - m_pConnectionsView - > setAcceptDrops ( true ) ; <nl> - m_pConnectionsView - > setEditTriggers ( QAbstractItemView : : NoEditTriggers ) ; <nl> - m_pConnectionsView - > setDragDropMode ( QAbstractItemView : : DropOnly ) ; <nl> - m_pConnectionsView - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ; <nl> - m_pConnectionsView - > setModel ( m_pConnectionModel ) ; <nl> - m_pConnectionsView - > installEventFilter ( this ) ; <nl> - m_pConnectionsView - > header ( ) - > setMinimumSectionSize ( 50 ) ; <nl> - m_pConnectionsView - > setIndentation ( 0 ) ; <nl> + m_pFilterProxyModel = new QDeepFilterProxyModel ( ) ; <nl> + m_pFilterProxyModel - > setSourceModel ( m_pConnectionModel ) ; <nl> + <nl> + m_pTreeView - > setEditTriggers ( QAbstractItemView : : NoEditTriggers ) ; <nl> + m_pTreeView - > setDragEnabled ( false ) ; <nl> + m_pTreeView - > setAcceptDrops ( true ) ; <nl> + m_pTreeView - > setDragDropMode ( QAbstractItemView : : DropOnly ) ; <nl> + m_pTreeView - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ; <nl> + m_pTreeView - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ; <nl> + m_pTreeView - > setModel ( m_pFilterProxyModel ) ; <nl> + m_pTreeView - > sortByColumn ( 0 , Qt : : AscendingOrder ) ; <nl> + m_pTreeView - > setIndentation ( 0 ) ; <nl> + m_pTreeView - > installEventFilter ( this ) ; <nl> + m_pTreeView - > header ( ) - > setMinimumSectionSize ( 50 ) ; <nl> <nl> - connect ( m_pConnectionsView , & CAdvancedTreeView : : customContextMenuRequested , [ & ] ( QPoint const & pos ) <nl> - { <nl> - int const selectionCount = m_pConnectionsView - > selectionModel ( ) - > selectedRows ( ) . count ( ) ; <nl> - <nl> - if ( selectionCount > 0 ) <nl> - { <nl> - QMenu * pContextMenu = new QMenu ( ) ; <nl> - <nl> - char const * actionName = " Remove Connection " ; <nl> - <nl> - if ( selectionCount > 1 ) <nl> - { <nl> - actionName = " Remove Connections " ; <nl> - } <nl> - <nl> - pContextMenu - > addAction ( tr ( actionName ) , [ & ] ( ) { RemoveSelectedConnection ( ) ; } ) ; <nl> - pContextMenu - > exec ( QCursor : : pos ( ) ) ; <nl> - } <nl> - } ) ; <nl> + QObject : : connect ( m_pTreeView , & CAudioTreeView : : customContextMenuRequested , this , & CConnectionsWidget : : OnContextMenu ) ; <nl> + QObject : : connect ( m_pTreeView - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , this , & CConnectionsWidget : : RefreshConnectionProperties ) ; <nl> <nl> - m_pConnectionPropertiesFrame = new QFrame ( this ) ; <nl> + m_pConnectionPropertiesFrame = new QFrame ( ) ; <nl> m_pConnectionPropertiesFrame - > setAutoFillBackground ( false ) ; <nl> m_pConnectionPropertiesFrame - > setStyleSheet ( QStringLiteral ( " # m_pConnectionPropertiesFrame { border : 1px solid # 363636 ; } " ) ) ; <nl> m_pConnectionPropertiesFrame - > setFrameShape ( QFrame : : Box ) ; <nl> CConnectionsWidget : : CConnectionsWidget ( QWidget * pParent ) <nl> m_pConnectionPropertiesFrame - > setLayout ( pLayout ) ; <nl> <nl> QSplitter * const pSplitter = new QSplitter ( Qt : : Vertical ) ; <nl> - pSplitter - > addWidget ( m_pConnectionsView ) ; <nl> + pSplitter - > addWidget ( m_pTreeView ) ; <nl> pSplitter - > addWidget ( m_pConnectionPropertiesFrame ) ; <nl> pSplitter - > setCollapsible ( 0 , false ) ; <nl> pSplitter - > setCollapsible ( 1 , false ) ; <nl> CConnectionsWidget : : CConnectionsWidget ( QWidget * pParent ) <nl> <nl> for ( int i = 2 ; i < count ; + + i ) <nl> { <nl> - m_pConnectionsView - > SetColumnVisible ( i , false ) ; <nl> + m_pTreeView - > SetColumnVisible ( i , false ) ; <nl> } <nl> <nl> / / Then hide the entire widget . <nl> CConnectionsWidget : : CConnectionsWidget ( QWidget * pParent ) <nl> if ( m_pControl = = pControl ) <nl> { <nl> / / clear the selection if a connection is removed <nl> - m_pConnectionsView - > selectionModel ( ) - > clear ( ) ; <nl> + m_pTreeView - > selectionModel ( ) - > clear ( ) ; <nl> RefreshConnectionProperties ( ) ; <nl> } <nl> } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> <nl> CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > signalImplementationAboutToChange . Connect ( [ & ] ( ) <nl> { <nl> - m_pConnectionsView - > selectionModel ( ) - > clear ( ) ; <nl> + m_pTreeView - > selectionModel ( ) - > clear ( ) ; <nl> RefreshConnectionProperties ( ) ; <nl> } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> } <nl> CConnectionsWidget : : ~ CConnectionsWidget ( ) <nl> CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > signalImplementationAboutToChange . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> } <nl> <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CConnectionsWidget : : Init ( ) <nl> - { <nl> - connect ( m_pConnectionsView - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , this , & CConnectionsWidget : : RefreshConnectionProperties ) ; <nl> - } <nl> - <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> bool CConnectionsWidget : : eventFilter ( QObject * pObject , QEvent * pEvent ) <nl> { <nl> bool CConnectionsWidget : : eventFilter ( QObject * pObject , QEvent * pEvent ) <nl> { <nl> QKeyEvent * pKeyEvent = static_cast < QKeyEvent * > ( pEvent ) ; <nl> <nl> - if ( pKeyEvent & & pKeyEvent - > key ( ) = = Qt : : Key_Delete & & pObject = = m_pConnectionsView ) <nl> + if ( pKeyEvent & & ( pKeyEvent - > key ( ) = = Qt : : Key_Delete ) & & ( pObject = = m_pTreeView ) ) <nl> { <nl> RemoveSelectedConnection ( ) ; <nl> return true ; <nl> } <nl> } <nl> + <nl> return QWidget : : eventFilter ( pObject , pEvent ) ; <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + void CConnectionsWidget : : OnContextMenu ( QPoint const & pos ) <nl> + { <nl> + int const selectionCount = m_pTreeView - > selectionModel ( ) - > selectedRows ( ) . count ( ) ; <nl> + <nl> + if ( selectionCount > 0 ) <nl> + { <nl> + QMenu * pContextMenu = new QMenu ( ) ; <nl> + <nl> + char const * actionName = " Remove Connection " ; <nl> + <nl> + if ( selectionCount > 1 ) <nl> + { <nl> + actionName = " Remove Connections " ; <nl> + } <nl> + <nl> + pContextMenu - > addAction ( tr ( actionName ) , [ & ] ( ) { RemoveSelectedConnection ( ) ; } ) ; <nl> + pContextMenu - > exec ( QCursor : : pos ( ) ) ; <nl> + } <nl> + } <nl> + <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CConnectionsWidget : : RemoveSelectedConnection ( ) <nl> { <nl> if ( m_pControl ) <nl> { <nl> - CQuestionDialog messageBox ; <nl> - QModelIndexList const selectedIndices = m_pConnectionsView - > selectionModel ( ) - > selectedRows ( ) ; <nl> + CQuestionDialog * messageBox = new CQuestionDialog ( ) ; <nl> + QModelIndexList const selectedIndices = m_pTreeView - > selectionModel ( ) - > selectedRows ( ) ; <nl> <nl> if ( ! selectedIndices . empty ( ) ) <nl> { <nl> void CConnectionsWidget : : RemoveSelectedConnection ( ) <nl> text = " Are you sure you want to delete the " + QString : : number ( size ) + " selected connections ? " ; <nl> } <nl> <nl> - messageBox . SetupQuestion ( " Audio Controls Editor " , text ) ; <nl> + messageBox - > SetupQuestion ( " Audio Controls Editor " , text ) ; <nl> <nl> - if ( messageBox . Execute ( ) = = QDialogButtonBox : : Yes ) <nl> + if ( messageBox - > Execute ( ) = = QDialogButtonBox : : Yes ) <nl> { <nl> CUndo undo ( " Disconnected Audio Control from Audio System " ) ; <nl> IAudioSystemEditor * pAudioSystemEditorImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> void CConnectionsWidget : : RemoveSelectedConnection ( ) <nl> std : : vector < IAudioSystemItem * > items ; <nl> items . reserve ( selectedIndices . size ( ) ) ; <nl> <nl> - for ( QModelIndex index : selectedIndices ) <nl> + for ( QModelIndex const index : selectedIndices ) <nl> { <nl> - CID id = index . data ( CConnectionModel : : eConnectionModelRoles_Id ) . toInt ( ) ; <nl> + CID const id = index . data ( static_cast < int > ( CConnectionModel : : EConnectionModelRoles : : Id ) ) . toInt ( ) ; <nl> items . push_back ( pAudioSystemEditorImpl - > GetControl ( id ) ) ; <nl> } <nl> <nl> void CConnectionsWidget : : SetControl ( CAudioControl * pControl ) <nl> void CConnectionsWidget : : Reload ( ) <nl> { <nl> m_pConnectionModel - > Init ( m_pControl ) ; <nl> - m_pConnectionsView - > selectionModel ( ) - > clear ( ) ; <nl> - m_pConnectionsView - > header ( ) - > setSectionResizeMode ( 0 , QHeaderView : : ResizeToContents ) ; <nl> + m_pTreeView - > selectionModel ( ) - > clear ( ) ; <nl> + m_pTreeView - > header ( ) - > setSectionResizeMode ( 0 , QHeaderView : : ResizeToContents ) ; <nl> RefreshConnectionProperties ( ) ; <nl> } <nl> <nl> void CConnectionsWidget : : Reload ( ) <nl> void CConnectionsWidget : : RefreshConnectionProperties ( ) <nl> { <nl> ConnectionPtr pConnection ; <nl> + <nl> if ( m_pControl ) <nl> { <nl> - QModelIndexList const selectedIndices = m_pConnectionsView - > selectionModel ( ) - > selectedIndexes ( ) ; <nl> + QModelIndexList const selectedIndices = m_pTreeView - > selectionModel ( ) - > selectedIndexes ( ) ; <nl> <nl> if ( ! selectedIndices . empty ( ) ) <nl> { <nl> void CConnectionsWidget : : RefreshConnectionProperties ( ) <nl> <nl> if ( index . isValid ( ) ) <nl> { <nl> - CID const id = index . data ( CConnectionModel : : eConnectionModelRoles_Id ) . toInt ( ) ; <nl> + CID const id = index . data ( static_cast < int > ( CConnectionModel : : EConnectionModelRoles : : Id ) ) . toInt ( ) ; <nl> pConnection = m_pControl - > GetConnection ( id ) ; <nl> } <nl> } <nl> void CConnectionsWidget : : RefreshConnectionProperties ( ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CConnectionsWidget : : BackupTreeViewStates ( ) <nl> { <nl> - m_pConnectionsView - > BackupSelection ( ) ; <nl> + m_pTreeView - > BackupSelection ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CConnectionsWidget : : RestoreTreeViewStates ( ) <nl> { <nl> - m_pConnectionsView - > RestoreSelection ( ) ; <nl> + m_pTreeView - > RestoreSelection ( ) ; <nl> } <nl> } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / ConnectionsWidget . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / ConnectionsWidget . h <nl> <nl> <nl> # include < QWidget > <nl> <nl> - class QVBoxLayout ; <nl> class QFrame ; <nl> class QPropertyTree ; <nl> + class QDeepFilterProxyModel ; <nl> <nl> namespace ACE <nl> { <nl> class CAudioControl ; <nl> class CConnectionModel ; <nl> - class CAdvancedTreeView ; <nl> + class CAudioTreeView ; <nl> <nl> - class CConnectionsWidget : public QWidget <nl> + class CConnectionsWidget final : public QWidget <nl> { <nl> + Q_OBJECT <nl> + <nl> public : <nl> <nl> CConnectionsWidget ( QWidget * pParent = nullptr ) ; <nl> virtual ~ CConnectionsWidget ( ) override ; <nl> <nl> - void Init ( ) ; <nl> void SetControl ( CAudioControl * pControl ) ; <nl> void Reload ( ) ; <nl> void BackupTreeViewStates ( ) ; <nl> void RestoreTreeViewStates ( ) ; <nl> <nl> + private slots : <nl> + <nl> + void OnContextMenu ( QPoint const & pos ) ; <nl> + <nl> private : <nl> <nl> + / / QObject <nl> bool eventFilter ( QObject * pObject , QEvent * pEvent ) override ; <nl> + / / ~ QObject <nl> + <nl> void RemoveSelectedConnection ( ) ; <nl> void RefreshConnectionProperties ( ) ; <nl> <nl> - CAudioControl * m_pControl ; <nl> - QFrame * m_pConnectionPropertiesFrame ; <nl> - QPropertyTree * m_pConnectionProperties ; <nl> - CConnectionModel * m_pConnectionModel ; <nl> - CAdvancedTreeView * m_pConnectionsView ; <nl> + CAudioControl * m_pControl ; <nl> + QFrame * m_pConnectionPropertiesFrame ; <nl> + QPropertyTree * m_pConnectionProperties ; <nl> + QDeepFilterProxyModel * m_pFilterProxyModel ; <nl> + CConnectionModel * m_pConnectionModel ; <nl> + CAudioTreeView * m_pTreeView ; <nl> } ; <nl> } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / EditorFmod / AudioSystemEditor_fmod . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / EditorFmod / AudioSystemEditor_fmod . cpp <nl> <nl> <nl> namespace ACE <nl> { <nl> - <nl> const string g_userSettingsFile = " % USER % / audiocontrolseditor_fmod . user " ; <nl> <nl> / / Paths <nl> ConnectionPtr CAudioSystemEditor_fmod : : CreateConnectionToControl ( EItemType contr <nl> } <nl> else if ( type = = eFmodItemType_EventParameter | | type = = eFmodItemType_SnapshotParameter ) <nl> { <nl> - if ( controlType = = eItemType_Parameter ) <nl> + if ( controlType = = EItemType : : Parameter ) <nl> { <nl> return std : : make_shared < CParamConnection > ( pMiddlewareControl - > GetId ( ) ) ; <nl> } <nl> - else if ( controlType = = eItemType_State ) <nl> + else if ( controlType = = EItemType : : State ) <nl> { <nl> return std : : make_shared < CParamToStateConnection > ( pMiddlewareControl - > GetId ( ) ) ; <nl> } <nl> ConnectionPtr CAudioSystemEditor_fmod : : CreateConnectionFromXMLNode ( XmlNodeRef pN <nl> case eFmodItemType_EventParameter : <nl> case eFmodItemType_SnapshotParameter : <nl> { <nl> - if ( controlType = = eItemType_Parameter ) <nl> + if ( controlType = = EItemType : : Parameter ) <nl> { <nl> std : : shared_ptr < CParamConnection > pConnection = std : : make_shared < CParamConnection > ( pItem - > GetId ( ) ) ; <nl> float mult = 1 . 0f ; <nl> ConnectionPtr CAudioSystemEditor_fmod : : CreateConnectionFromXMLNode ( XmlNodeRef pN <nl> pConnection - > shift = shift ; <nl> return pConnection ; <nl> } <nl> - else if ( controlType = = eItemType_State ) <nl> + else if ( controlType = = EItemType : : State ) <nl> { <nl> std : : shared_ptr < CParamToStateConnection > pConnection = std : : make_shared < CParamToStateConnection > ( pItem - > GetId ( ) ) ; <nl> string value = pNode - > getAttr ( g_valueAttribute ) ; <nl> XmlNodeRef CAudioSystemEditor_fmod : : CreateXMLNodeFromConnection ( const Connection <nl> { <nl> pNode - > setAttr ( g_nameAttribute , pItem - > GetName ( ) ) ; <nl> pNode - > setAttr ( g_pathAttribute , GetFullPathName ( pItem - > GetParent ( ) ) ) ; <nl> - if ( controlType = = eItemType_State ) <nl> + if ( controlType = = EItemType : : State ) <nl> { <nl> auto pRtpcConnection = static_cast < const CParamToStateConnection * > ( pConnection . get ( ) ) ; <nl> if ( pRtpcConnection ) <nl> XmlNodeRef CAudioSystemEditor_fmod : : CreateXMLNodeFromConnection ( const Connection <nl> pNode - > setAttr ( g_valueAttribute , pRtpcConnection - > m_value ) ; <nl> } <nl> } <nl> - else if ( controlType = = eItemType_Parameter ) <nl> + else if ( controlType = = EItemType : : Parameter ) <nl> { <nl> auto pParamConnection = static_cast < const CParamConnection * > ( pConnection . get ( ) ) ; <nl> if ( pParamConnection - > mult ! = 1 . 0f ) <nl> ACE : : EItemType CAudioSystemEditor_fmod : : ImplTypeToATLType ( ItemType type ) const <nl> switch ( type ) <nl> { <nl> case eFmodItemType_Event : <nl> - return eItemType_Trigger ; <nl> + return EItemType : : Trigger ; <nl> case eFmodItemType_EventParameter : <nl> - return eItemType_Parameter ; <nl> + return EItemType : : Parameter ; <nl> case eFmodItemType_Snapshot : <nl> - return eItemType_Trigger ; <nl> + return EItemType : : Trigger ; <nl> case eFmodItemType_SnapshotParameter : <nl> - return eItemType_Parameter ; <nl> + return EItemType : : Parameter ; <nl> case eFmodItemType_Bank : <nl> - return eItemType_Preload ; <nl> + return EItemType : : Preload ; <nl> case eFmodItemType_Return : <nl> - return eItemType_Environment ; <nl> + return EItemType : : Environment ; <nl> } <nl> - return eItemType_Invalid ; <nl> + return EItemType : : Invalid ; <nl> } <nl> <nl> ACE : : TImplControlTypeMask CAudioSystemEditor_fmod : : GetCompatibleTypes ( EItemType controlType ) const <nl> { <nl> switch ( controlType ) <nl> { <nl> - case eItemType_Trigger : <nl> + case EItemType : : Trigger : <nl> return eFmodItemType_Event | eFmodItemType_Snapshot ; <nl> break ; <nl> - case eItemType_Parameter : <nl> + case EItemType : : Parameter : <nl> return eFmodItemType_EventParameter | eFmodItemType_SnapshotParameter ; <nl> break ; <nl> - case eItemType_Preload : <nl> + case EItemType : : Preload : <nl> return eFmodItemType_Bank ; <nl> break ; <nl> - case eItemType_State : <nl> + case EItemType : : State : <nl> return eFmodItemType_EventParameter | eFmodItemType_SnapshotParameter ; <nl> break ; <nl> - case eItemType_Environment : <nl> + case EItemType : : Environment : <nl> return eFmodItemType_Return ; <nl> break ; <nl> } <nl> SERIALIZATION_ENUM_BEGIN ( EFmodEventType , " Event Type " ) <nl> SERIALIZATION_ENUM ( eFmodEventType_Start , " start " , " Start " ) <nl> SERIALIZATION_ENUM ( eFmodEventType_Stop , " stop " , " Stop " ) <nl> SERIALIZATION_ENUM_END ( ) <nl> - <nl> - } <nl> + } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / EditorPortAudio / AudioSystemEditor . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / EditorPortAudio / AudioSystemEditor . cpp <nl> XmlNodeRef CAudioSystemEditor : : CreateXMLNodeFromConnection ( const ConnectionPtr p <nl> { <nl> std : : shared_ptr < const CConnection > pSDLMixerConnection = std : : static_pointer_cast < const CConnection > ( pConnection ) ; <nl> const IAudioSystemItem * pControl = GetControl ( pConnection - > GetID ( ) ) ; <nl> - if ( pControl & & pSDLMixerConnection & & eATLControlType = = eItemType_Trigger ) <nl> + if ( pControl & & pSDLMixerConnection & & eATLControlType = = EItemType : : Trigger ) <nl> { <nl> XmlNodeRef pConnectionNode = GetISystem ( ) - > CreateXmlNode ( s_eventConnectionTag ) ; <nl> pConnectionNode - > setAttr ( s_itemNameTag , pControl - > GetName ( ) ) ; <nl> ACE : : EItemType CAudioSystemEditor : : ImplTypeToATLType ( ItemType type ) const <nl> switch ( type ) <nl> { <nl> case ePortAudioTypes_Event : <nl> - return eItemType_Trigger ; <nl> + return EItemType : : Trigger ; <nl> } <nl> - return eItemType_Invalid ; <nl> + return EItemType : : Invalid ; <nl> } <nl> <nl> ACE : : TImplControlTypeMask CAudioSystemEditor : : GetCompatibleTypes ( EItemType eATLControlType ) const <nl> { <nl> switch ( eATLControlType ) <nl> { <nl> - case eItemType_Trigger : <nl> + case EItemType : : Trigger : <nl> return ePortAudioTypes_Event ; <nl> } <nl> return AUDIO_SYSTEM_INVALID_TYPE ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / EditorSDLMixer / AudioSystemEditor_sdlmixer . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / EditorSDLMixer / AudioSystemEditor_sdlmixer . cpp <nl> XmlNodeRef CAudioSystemEditor_sdlmixer : : CreateXMLNodeFromConnection ( const Connec <nl> { <nl> std : : shared_ptr < const CSdlMixerConnection > pSDLMixerConnection = std : : static_pointer_cast < const CSdlMixerConnection > ( pConnection ) ; <nl> const IAudioSystemItem * pControl = GetControl ( pConnection - > GetID ( ) ) ; <nl> - if ( pControl & & pSDLMixerConnection & & eATLControlType = = eItemType_Trigger ) <nl> + if ( pControl & & pSDLMixerConnection & & eATLControlType = = EItemType : : Trigger ) <nl> { <nl> XmlNodeRef pConnectionNode = GetISystem ( ) - > CreateXmlNode ( s_eventConnectionTag ) ; <nl> pConnectionNode - > setAttr ( s_itemNameTag , pControl - > GetName ( ) ) ; <nl> ACE : : EItemType CAudioSystemEditor_sdlmixer : : ImplTypeToATLType ( ItemType type ) con <nl> switch ( type ) <nl> { <nl> case eSdlMixerTypes_Event : <nl> - return eItemType_Trigger ; <nl> + return EItemType : : Trigger ; <nl> } <nl> - return eItemType_Invalid ; <nl> + return EItemType : : Invalid ; <nl> } <nl> <nl> ACE : : TImplControlTypeMask CAudioSystemEditor_sdlmixer : : GetCompatibleTypes ( EItemType eATLControlType ) const <nl> { <nl> switch ( eATLControlType ) <nl> { <nl> - case eItemType_Trigger : <nl> + case EItemType : : Trigger : <nl> return eSdlMixerTypes_Event ; <nl> } <nl> return AUDIO_SYSTEM_INVALID_TYPE ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / EditorWwise / AudioSystemEditor_wwise . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / EditorWwise / AudioSystemEditor_wwise . cpp <nl> ConnectionPtr CAudioSystemEditor_wwise : : CreateConnectionToControl ( EItemType eATL <nl> { <nl> switch ( eATLControlType ) <nl> { <nl> - case EItemType : : eItemType_Parameter : <nl> + case EItemType : : Parameter : <nl> { <nl> return std : : make_shared < CRtpcConnection > ( pMiddlewareControl - > GetId ( ) ) ; <nl> } <nl> - case EItemType : : eItemType_State : <nl> + case EItemType : : State : <nl> { <nl> return std : : make_shared < CStateToRtpcConnection > ( pMiddlewareControl - > GetId ( ) ) ; <nl> } <nl> ConnectionPtr CAudioSystemEditor_wwise : : CreateConnectionFromXMLNode ( XmlNodeRef p <nl> { <nl> switch ( eATLControlType ) <nl> { <nl> - case EItemType : : eItemType_Parameter : <nl> + case EItemType : : Parameter : <nl> { <nl> RtpcConnectionPtr pConnection = std : : make_shared < CRtpcConnection > ( pControl - > GetId ( ) ) ; <nl> <nl> ConnectionPtr CAudioSystemEditor_wwise : : CreateConnectionFromXMLNode ( XmlNodeRef p <nl> pNode - > getAttr ( g_shiftAttribute , pConnection - > shift ) ; <nl> return pConnection ; <nl> } <nl> - case EItemType : : eItemType_State : <nl> + case EItemType : : State : <nl> { <nl> StateConnectionPtr pConnection = std : : make_shared < CStateToRtpcConnection > ( pControl - > GetId ( ) ) ; <nl> pNode - > getAttr ( g_valueAttribute , pConnection - > value ) ; <nl> XmlNodeRef CAudioSystemEditor_wwise : : CreateXMLNodeFromConnection ( const Connectio <nl> pConnectionNode = GetISystem ( ) - > CreateXmlNode ( TypeToTag ( pControl - > GetType ( ) ) ) ; <nl> pConnectionNode - > setAttr ( g_nameAttribute , pControl - > GetName ( ) ) ; <nl> <nl> - if ( eATLControlType = = eItemType_Parameter ) <nl> + if ( eATLControlType = = EItemType : : Parameter ) <nl> { <nl> std : : shared_ptr < const CRtpcConnection > pRtpcConnection = std : : static_pointer_cast < const CRtpcConnection > ( pConnection ) ; <nl> if ( pRtpcConnection - > mult ! = 1 . 0f ) <nl> XmlNodeRef CAudioSystemEditor_wwise : : CreateXMLNodeFromConnection ( const Connectio <nl> } <nl> <nl> } <nl> - else if ( eATLControlType = = eItemType_State ) <nl> + else if ( eATLControlType = = EItemType : : State ) <nl> { <nl> std : : shared_ptr < const CStateToRtpcConnection > pStateConnection = std : : static_pointer_cast < const CStateToRtpcConnection > ( pConnection ) ; <nl> pConnectionNode - > setAttr ( g_valueAttribute , pStateConnection - > value ) ; <nl> ACE : : EItemType CAudioSystemEditor_wwise : : ImplTypeToATLType ( ItemType type ) const <nl> switch ( type ) <nl> { <nl> case eWwiseItemTypes_Event : <nl> - return eItemType_Trigger ; <nl> + return EItemType : : Trigger ; <nl> break ; <nl> case eWwiseItemTypes_Rtpc : <nl> - return eItemType_Parameter ; <nl> + return EItemType : : Parameter ; <nl> break ; <nl> case eWwiseItemTypes_Switch : <nl> case eWwiseItemTypes_State : <nl> - return eItemType_State ; <nl> + return EItemType : : State ; <nl> break ; <nl> case eWwiseItemTypes_AuxBus : <nl> - return eItemType_Environment ; <nl> + return EItemType : : Environment ; <nl> break ; <nl> case eWwiseItemTypes_SoundBank : <nl> - return eItemType_Preload ; <nl> + return EItemType : : Preload ; <nl> break ; <nl> case eWwiseItemTypes_StateGroup : <nl> case eWwiseItemTypes_SwitchGroup : <nl> - return eItemType_Switch ; <nl> + return EItemType : : Switch ; <nl> break ; <nl> } <nl> - return eItemType_Invalid ; <nl> + return EItemType : : Invalid ; <nl> } <nl> <nl> ACE : : TImplControlTypeMask CAudioSystemEditor_wwise : : GetCompatibleTypes ( EItemType atlControlType ) const <nl> { <nl> switch ( atlControlType ) <nl> { <nl> - case eItemType_Trigger : <nl> + case EItemType : : Trigger : <nl> return eWwiseItemTypes_Event ; <nl> break ; <nl> - case eItemType_Parameter : <nl> + case EItemType : : Parameter : <nl> return eWwiseItemTypes_Rtpc ; <nl> break ; <nl> - case eItemType_Switch : <nl> + case EItemType : : Switch : <nl> return AUDIO_SYSTEM_INVALID_TYPE ; <nl> break ; <nl> - case eItemType_State : <nl> + case EItemType : : State : <nl> return ( eWwiseItemTypes_Switch | eWwiseItemTypes_State | eWwiseItemTypes_Rtpc ) ; <nl> break ; <nl> - case eItemType_Environment : <nl> + case EItemType : : Environment : <nl> return ( eWwiseItemTypes_AuxBus | eWwiseItemTypes_Switch | eWwiseItemTypes_State | eWwiseItemTypes_Rtpc ) ; <nl> break ; <nl> - case eItemType_Preload : <nl> + case EItemType : : Preload : <nl> return eWwiseItemTypes_SoundBank ; <nl> break ; <nl> } <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / FileMonitor . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / FileMonitor . cpp <nl> <nl> namespace ACE <nl> { <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CFileMonitor : : CFileMonitor ( CAudioControlsEditorWindow * window , int delay ) <nl> + CFileMonitor : : CFileMonitor ( CAudioControlsEditorWindow * const window , int const delay ) <nl> : m_window ( window ) <nl> , m_delay ( delay ) <nl> { <nl> void CFileMonitor : : Disable ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CFileMonitorSystem : : CFileMonitorSystem ( CAudioControlsEditorWindow * window , int delay ) <nl> + CFileMonitorSystem : : CFileMonitorSystem ( CAudioControlsEditorWindow * const window , int const delay ) <nl> : CFileMonitor ( window , delay ) <nl> , m_assetFolder ( Utils : : GetAssetFolder ( ) ) <nl> , m_delayTimer ( new QTimer ( ) ) <nl> void CFileMonitorSystem : : ReloadData ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CFileMonitorMiddleware : : CFileMonitorMiddleware ( CAudioControlsEditorWindow * window , int delay ) <nl> + CFileMonitorMiddleware : : CFileMonitorMiddleware ( CAudioControlsEditorWindow * const window , int const delay ) <nl> : CFileMonitor ( window , delay ) <nl> { <nl> Enable ( ) ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / FileMonitor . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / FileMonitor . h <nl> class CFileMonitor : public QTimer , public IFileChangeListener <nl> <nl> protected : <nl> <nl> - CFileMonitor ( CAudioControlsEditorWindow * window , int delay ) ; <nl> + CFileMonitor ( CAudioControlsEditorWindow * const window , int const delay ) ; <nl> <nl> virtual ~ CFileMonitor ( ) override ; <nl> <nl> class CFileMonitor : public QTimer , public IFileChangeListener <nl> virtual void ReloadData ( ) { } <nl> <nl> CAudioControlsEditorWindow * m_window ; <nl> - int m_delay ; <nl> + int const m_delay ; <nl> } ; <nl> <nl> class CFileMonitorSystem final : public CFileMonitor <nl> class CFileMonitorSystem final : public CFileMonitor <nl> <nl> public : <nl> <nl> - CFileMonitorSystem ( CAudioControlsEditorWindow * window , int delay ) ; <nl> + CFileMonitorSystem ( CAudioControlsEditorWindow * const window , int const delay ) ; <nl> <nl> void Enable ( ) ; <nl> void EnableDelayed ( ) ; <nl> class CFileMonitorMiddleware final : public CFileMonitor <nl> <nl> public : <nl> <nl> - CFileMonitorMiddleware ( CAudioControlsEditorWindow * window , int delay ) ; <nl> + CFileMonitorMiddleware ( CAudioControlsEditorWindow * const window , int const delay ) ; <nl> <nl> void Enable ( ) ; <nl> <nl> deleted file mode 100644 <nl> index e8266345d0 . . 0000000000 <nl> Binary files a / Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / Bank . ico and / dev / null differ <nl> deleted file mode 100644 <nl> index e56eeffb10 . . 0000000000 <nl> Binary files a / Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / Config_Blue . ico and / dev / null differ <nl> deleted file mode 100644 <nl> index 8921f7a3af . . 0000000000 <nl> Binary files a / Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / Folder . ico and / dev / null differ <nl> deleted file mode 100644 <nl> index 7e43470c1f . . 0000000000 <nl> Binary files a / Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / Load . ico and / dev / null differ <nl> deleted file mode 100644 <nl> index 1e5a984bf8 . . 0000000000 <nl> Binary files a / Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / Options . ico and / dev / null differ <nl> Binary files a / Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / Preload . ico and b / Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / Preload . ico differ <nl> deleted file mode 100644 <nl> index 56912bf687 . . 0000000000 <nl> Binary files a / Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / Save . ico and / dev / null differ <nl> deleted file mode 100644 <nl> index 584f89b2ab . . 0000000000 <nl> Binary files a / Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / Search . ico and / dev / null differ <nl> similarity index 100 % <nl> rename from Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / Property . ico <nl> rename to Code / Sandbox / Plugins / EditorAudioControlsEditor / Icons / State . ico <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / MiddlewareDataModel . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / MiddlewareDataModel . cpp <nl> <nl> <nl> # include " MiddlewareDataModel . h " <nl> # include " IAudioSystemEditor . h " <nl> - # include " IAudioSystemItem . h " <nl> # include " AudioControlsEditorPlugin . h " <nl> # include " ImplementationManager . h " <nl> <nl> + # include < IAudioSystemItem . h > <nl> # include < CrySystem / File / CryFile . h > / / Includes CryPath . h in correct order . <nl> # include < QtUtil . h > <nl> # include < CrySandbox / CrySignal . h > <nl> char const * const CMiddlewareDataModel : : ms_szMimeType = " application / cryengine - a <nl> CMiddlewareDataModel : : CMiddlewareDataModel ( ) <nl> : m_pAudioSystem ( CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ) <nl> { <nl> - <nl> CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > signalImplementationChanged . Connect ( [ & ] ( ) <nl> - { <nl> - m_pAudioSystem = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> - beginResetModel ( ) ; <nl> - endResetModel ( ) ; <nl> - } ) ; <nl> + { <nl> + m_pAudioSystem = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> + beginResetModel ( ) ; <nl> + endResetModel ( ) ; <nl> + } ) ; <nl> <nl> CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > signalImplementationAboutToChange . Connect ( [ & ] ( ) <nl> - { <nl> - beginResetModel ( ) ; <nl> - m_pAudioSystem = nullptr ; <nl> - endResetModel ( ) ; <nl> - } ) ; <nl> + { <nl> + beginResetModel ( ) ; <nl> + m_pAudioSystem = nullptr ; <nl> + endResetModel ( ) ; <nl> + } ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - int CMiddlewareDataModel : : rowCount ( const QModelIndex & parent ) const <nl> + int CMiddlewareDataModel : : rowCount ( QModelIndex const & parent ) const <nl> { <nl> if ( m_pAudioSystem ) <nl> { <nl> IAudioSystemItem * pItem = ItemFromIndex ( parent ) ; <nl> + <nl> if ( ! pItem ) <nl> { <nl> / / if not valid it must be a top level item so get root <nl> int CMiddlewareDataModel : : rowCount ( const QModelIndex & parent ) const <nl> return pItem - > ChildCount ( ) ; <nl> } <nl> } <nl> + <nl> return 0 ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - int CMiddlewareDataModel : : columnCount ( const QModelIndex & parent ) const <nl> + int CMiddlewareDataModel : : columnCount ( QModelIndex const & parent ) const <nl> { <nl> - return eAudioSystemColumns_Count ; <nl> + return static_cast < int > ( EMiddlewareDataColumns : : Count ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - QVariant CMiddlewareDataModel : : data ( const QModelIndex & index , int role ) const <nl> + QVariant CMiddlewareDataModel : : data ( QModelIndex const & index , int role ) const <nl> { <nl> if ( m_pAudioSystem ) <nl> { <nl> QVariant CMiddlewareDataModel : : data ( const QModelIndex & index , int role ) const <nl> } <nl> <nl> IAudioSystemItem * pItem = ItemFromIndex ( index ) ; <nl> + <nl> if ( pItem ) <nl> { <nl> switch ( index . column ( ) ) <nl> { <nl> - case eAudioSystemColumns_Name : <nl> + case static_cast < int > ( EMiddlewareDataColumns : : Name ) : <nl> { <nl> switch ( role ) <nl> { <nl> QVariant CMiddlewareDataModel : : data ( const QModelIndex & index , int role ) const <nl> { <nl> return QColor ( 36 , 180 , 245 ) ; <nl> } <nl> - else if ( ! pItem - > IsConnected ( ) & & m_pAudioSystem - > ImplTypeToATLType ( pItem - > GetType ( ) ) ! = eItemType_Invalid ) <nl> + else if ( ! pItem - > IsConnected ( ) & & ( m_pAudioSystem - > ImplTypeToATLType ( pItem - > GetType ( ) ) ! = EItemType : : Invalid ) ) <nl> { <nl> / / Tint non connected controls that can actually be connected to something ( ie . exclude folders ) <nl> return QColor ( 255 , 150 , 50 ) ; <nl> QVariant CMiddlewareDataModel : : data ( const QModelIndex & index , int role ) const <nl> return tr ( " Item is not connected to any ATL control " ) ; <nl> } <nl> break ; <nl> - case eAudioSystemAttributes_Type : <nl> + case static_cast < int > ( EMiddlewareDataAttributes : : Type ) : <nl> return pItem - > GetType ( ) ; <nl> - case eAudioSystemAttributes_Connected : <nl> + case static_cast < int > ( EMiddlewareDataAttributes : : Connected ) : <nl> return pItem - > IsConnected ( ) ; <nl> - case eAudioSystemAttributes_Placeholder : <nl> + case static_cast < int > ( EMiddlewareDataAttributes : : Placeholder ) : <nl> return pItem - > IsPlaceholder ( ) ; <nl> - case eAudioSystemAttributes_Localized : <nl> + case static_cast < int > ( EMiddlewareDataAttributes : : Localized ) : <nl> return pItem - > IsLocalised ( ) ; <nl> } <nl> } <nl> QVariant CMiddlewareDataModel : : headerData ( int section , Qt : : Orientation orientati <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - Qt : : ItemFlags CMiddlewareDataModel : : flags ( const QModelIndex & index ) const <nl> + Qt : : ItemFlags CMiddlewareDataModel : : flags ( QModelIndex const & index ) const <nl> { <nl> Qt : : ItemFlags flag = QAbstractItemModel : : flags ( index ) ; <nl> + <nl> if ( index . isValid ( ) & & m_pAudioSystem ) <nl> { <nl> IAudioSystemItem * pItem = ItemFromIndex ( index ) ; <nl> - if ( pItem & & ! pItem - > IsPlaceholder ( ) & & m_pAudioSystem - > ImplTypeToATLType ( pItem - > GetType ( ) ) ! = eItemType_NumTypes ) <nl> + <nl> + if ( pItem & & ! pItem - > IsPlaceholder ( ) & & ( m_pAudioSystem - > ImplTypeToATLType ( pItem - > GetType ( ) ) ! = EItemType : : NumTypes ) ) <nl> { <nl> flag | = Qt : : ItemIsDragEnabled ; <nl> } <nl> } <nl> + <nl> return flag ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - QModelIndex CMiddlewareDataModel : : index ( int row , int column , const QModelIndex & parent / * = QModelIndex ( ) * / ) const <nl> + QModelIndex CMiddlewareDataModel : : index ( int row , int column , QModelIndex const & parent / * = QModelIndex ( ) * / ) const <nl> { <nl> if ( m_pAudioSystem ) <nl> { <nl> if ( ( row > = 0 ) & & ( column > = 0 ) ) <nl> { <nl> IAudioSystemItem * pParent = ItemFromIndex ( parent ) ; <nl> + <nl> if ( ! pParent ) <nl> { <nl> pParent = m_pAudioSystem - > GetRoot ( ) ; <nl> } <nl> + <nl> if ( pParent & & pParent - > ChildCount ( ) > row ) <nl> { <nl> IAudioSystemItem * pItem = pParent - > GetChildAt ( row ) ; <nl> + <nl> if ( pItem ) <nl> { <nl> return createIndex ( row , column , reinterpret_cast < quintptr > ( pItem ) ) ; <nl> QModelIndex CMiddlewareDataModel : : index ( int row , int column , const QModelIndex & <nl> } <nl> } <nl> } <nl> + <nl> return QModelIndex ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - QModelIndex CMiddlewareDataModel : : parent ( const QModelIndex & index ) const <nl> + QModelIndex CMiddlewareDataModel : : parent ( QModelIndex const & index ) const <nl> { <nl> if ( index . isValid ( ) ) <nl> { <nl> IAudioSystemItem * pItem = ItemFromIndex ( index ) ; <nl> + <nl> if ( pItem ) <nl> { <nl> return IndexFromItem ( pItem - > GetParent ( ) ) ; <nl> } <nl> } <nl> + <nl> return QModelIndex ( ) ; <nl> <nl> } <nl> QStringList CMiddlewareDataModel : : mimeTypes ( ) const <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - QMimeData * CMiddlewareDataModel : : mimeData ( const QModelIndexList & indexes ) const <nl> + QMimeData * CMiddlewareDataModel : : mimeData ( QModelIndexList const & indexes ) const <nl> { <nl> QMimeData * pData = QAbstractItemModel : : mimeData ( indexes ) ; <nl> QByteArray byteArray ; <nl> QDataStream stream ( & byteArray , QIODevice : : ReadWrite ) ; <nl> <nl> - for ( auto index : indexes ) <nl> + for ( auto const index : indexes ) <nl> { <nl> IAudioSystemItem * pItem = ItemFromIndex ( index ) ; <nl> + <nl> if ( pItem ) <nl> { <nl> stream < < pItem - > GetId ( ) ; <nl> } <nl> } <nl> + <nl> pData - > setData ( ms_szMimeType , byteArray ) ; <nl> return pData ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - IAudioSystemItem * CMiddlewareDataModel : : ItemFromIndex ( const QModelIndex & index ) const <nl> + IAudioSystemItem * CMiddlewareDataModel : : ItemFromIndex ( QModelIndex const & index ) const <nl> { <nl> if ( ( index . row ( ) < 0 ) | | ( index . column ( ) < 0 ) ) <nl> { <nl> return nullptr ; <nl> } <nl> + <nl> return static_cast < IAudioSystemItem * > ( index . internalPointer ( ) ) ; <nl> } <nl> <nl> QModelIndex CMiddlewareDataModel : : IndexFromItem ( IAudioSystemItem * pItem ) const <nl> if ( pItem ) <nl> { <nl> IAudioSystemItem * pParent = pItem - > GetParent ( ) ; <nl> + <nl> if ( ! pParent ) <nl> { <nl> pParent = m_pAudioSystem - > GetRoot ( ) ; <nl> QModelIndex CMiddlewareDataModel : : IndexFromItem ( IAudioSystemItem * pItem ) const <nl> <nl> if ( pParent ) <nl> { <nl> - const int size = pParent - > ChildCount ( ) ; <nl> + int const size = pParent - > ChildCount ( ) ; <nl> + <nl> for ( int i = 0 ; i < size ; + + i ) <nl> { <nl> if ( pParent - > GetChildAt ( i ) = = pItem ) <nl> QModelIndex CMiddlewareDataModel : : IndexFromItem ( IAudioSystemItem * pItem ) const <nl> } <nl> } <nl> } <nl> + <nl> return QModelIndex ( ) ; <nl> } <nl> <nl> bool CMiddlewareDataFilterProxyModel : : rowMatchesFilter ( int source_row , const QMo <nl> { <nl> if ( QDeepFilterProxyModel : : rowMatchesFilter ( source_row , source_parent ) ) <nl> { <nl> - QModelIndex index = sourceModel ( ) - > index ( source_row , 0 , source_parent ) ; <nl> + QModelIndex const index = sourceModel ( ) - > index ( source_row , 0 , source_parent ) ; <nl> + <nl> if ( index . isValid ( ) ) <nl> { <nl> / / Hide placeholder <nl> - if ( sourceModel ( ) - > data ( index , CMiddlewareDataModel : : eAudioSystemAttributes_Placeholder ) . toBool ( ) ) <nl> + if ( sourceModel ( ) - > data ( index , static_cast < int > ( CMiddlewareDataModel : : EMiddlewareDataAttributes : : Placeholder ) ) . toBool ( ) ) <nl> { <nl> return false ; <nl> } <nl> + <nl> if ( m_bHideConnected ) <nl> { <nl> - if ( sourceModel ( ) - > data ( index , CMiddlewareDataModel : : eAudioSystemAttributes_Connected ) . toBool ( ) ) <nl> + if ( sourceModel ( ) - > data ( index , static_cast < int > ( CMiddlewareDataModel : : EMiddlewareDataAttributes : : Connected ) ) . toBool ( ) ) <nl> { <nl> return false ; <nl> } <nl> bool CMiddlewareDataFilterProxyModel : : rowMatchesFilter ( int source_row , const QMo <nl> } <nl> } <nl> } <nl> + <nl> return true ; <nl> } <nl> } <nl> void CMiddlewareDataFilterProxyModel : : SetAllowedControlsMask ( uint allowedControl <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CMiddlewareDataFilterProxyModel : : SetHideConnected ( bool bHideConnected ) <nl> + void CMiddlewareDataFilterProxyModel : : SetHideConnected ( bool const bHideConnected ) <nl> { <nl> m_bHideConnected = bHideConnected ; <nl> invalidate ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - bool CMiddlewareDataFilterProxyModel : : lessThan ( const QModelIndex & left , const QModelIndex & right ) const <nl> + bool CMiddlewareDataFilterProxyModel : : lessThan ( QModelIndex const & left , QModelIndex const & right ) const <nl> { <nl> if ( left . column ( ) = = right . column ( ) ) <nl> { <nl> - const bool bLeftHasChildren = ( sourceModel ( ) - > rowCount ( left ) > 0 ) ; <nl> - const bool bRightHasChildren = ( sourceModel ( ) - > rowCount ( right ) > 0 ) ; <nl> + bool const bLeftHasChildren = ( sourceModel ( ) - > rowCount ( left ) > 0 ) ; <nl> + bool const bRightHasChildren = ( sourceModel ( ) - > rowCount ( right ) > 0 ) ; <nl> <nl> if ( bLeftHasChildren = = bRightHasChildren ) <nl> { <nl> - QVariant valueLeft = sourceModel ( ) - > data ( left , Qt : : DisplayRole ) ; <nl> - QVariant valueRight = sourceModel ( ) - > data ( right , Qt : : DisplayRole ) ; <nl> + QVariant const valueLeft = sourceModel ( ) - > data ( left , Qt : : DisplayRole ) ; <nl> + QVariant const valueRight = sourceModel ( ) - > data ( right , Qt : : DisplayRole ) ; <nl> return valueLeft < valueRight ; <nl> } <nl> else <nl> namespace AudioModelUtils <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void DecodeImplMimeData ( const QMimeData * pData , std : : vector < IAudioSystemItem * > & outItems ) <nl> { <nl> - ACE : : IAudioSystemEditor * pAudioSystemEditorImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> + IAudioSystemEditor * pAudioSystemEditorImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> QByteArray encoded = pData - > data ( CMiddlewareDataModel : : ms_szMimeType ) ; <nl> QDataStream stream ( & encoded , QIODevice : : ReadOnly ) ; <nl> while ( ! stream . atEnd ( ) ) <nl> { <nl> CID id ; <nl> stream > > id ; <nl> + <nl> if ( id ! = ACE_INVALID_ID ) <nl> { <nl> IAudioSystemItem * pAudioSystemControl = pAudioSystemEditorImpl - > GetControl ( id ) ; <nl> + <nl> if ( pAudioSystemControl ) <nl> { <nl> outItems . push_back ( pAudioSystemControl ) ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / MiddlewareDataModel . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / MiddlewareDataModel . h <nl> <nl> <nl> # pragma once <nl> <nl> - # include < QAbstractItemModel > <nl> # include < ProxyModels / DeepFilterProxyModel . h > <nl> <nl> namespace ACE <nl> class IAudioSystemItem ; <nl> <nl> namespace AudioModelUtils <nl> { <nl> - void DecodeImplMimeData ( const QMimeData * pData , std : : vector < IAudioSystemItem * > & outItems ) ; <nl> + void DecodeImplMimeData ( const QMimeData * pData , std : : vector < IAudioSystemItem * > & outItems ) ; <nl> } / / namespace AudioModelUtils <nl> <nl> class CMiddlewareDataModel final : public QAbstractItemModel <nl> { <nl> - <nl> public : <nl> <nl> - enum EAudioSystemColumns <nl> + enum class EMiddlewareDataColumns <nl> { <nl> - eAudioSystemColumns_Name , <nl> - eAudioSystemColumns_Count , <nl> + Name , <nl> + Count , <nl> } ; <nl> <nl> / / TODO : Should be replaced with the new attribute system <nl> - enum EAudioSystemAttributes <nl> + enum class EMiddlewareDataAttributes <nl> { <nl> - eAudioSystemAttributes_Type = Qt : : UserRole + 1 , <nl> - eAudioSystemAttributes_Connected , <nl> - eAudioSystemAttributes_Placeholder , <nl> - eAudioSystemAttributes_Localized , <nl> + Type = Qt : : UserRole + 1 , <nl> + Connected , <nl> + Placeholder , <nl> + Localized , <nl> } ; <nl> <nl> CMiddlewareDataModel ( ) ; <nl> <nl> / / QAbstractItemModel <nl> - virtual int rowCount ( const QModelIndex & parent ) const override ; <nl> - virtual int columnCount ( const QModelIndex & parent ) const override ; <nl> - virtual QVariant data ( const QModelIndex & index , int role ) const override ; <nl> + virtual int rowCount ( QModelIndex const & parent ) const override ; <nl> + virtual int columnCount ( QModelIndex const & parent ) const override ; <nl> + virtual QVariant data ( QModelIndex const & index , int role ) const override ; <nl> virtual QVariant headerData ( int section , Qt : : Orientation orientation , int role = Qt : : DisplayRole ) const override ; <nl> - virtual Qt : : ItemFlags flags ( const QModelIndex & index ) const override ; <nl> - virtual QModelIndex index ( int row , int column , const QModelIndex & parent = QModelIndex ( ) ) const override ; <nl> - virtual QModelIndex parent ( const QModelIndex & index ) const override ; <nl> + virtual Qt : : ItemFlags flags ( QModelIndex const & index ) const override ; <nl> + virtual QModelIndex index ( int row , int column , QModelIndex const & parent = QModelIndex ( ) ) const override ; <nl> + virtual QModelIndex parent ( QModelIndex const & index ) const override ; <nl> virtual Qt : : DropActions supportedDragActions ( ) const override ; <nl> virtual QStringList mimeTypes ( ) const override ; <nl> - virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const override ; <nl> + virtual QMimeData * mimeData ( QModelIndexList const & indexes ) const override ; <nl> / / ~ QAbstractItemModel <nl> <nl> - IAudioSystemItem * ItemFromIndex ( const QModelIndex & index ) const ; <nl> + IAudioSystemItem * ItemFromIndex ( QModelIndex const & index ) const ; <nl> QModelIndex IndexFromItem ( IAudioSystemItem * pItem ) const ; <nl> void Reset ( ) ; <nl> <nl> static char const * const ms_szMimeType ; <nl> <nl> private : <nl> + <nl> IAudioSystemEditor * m_pAudioSystem ; <nl> } ; <nl> <nl> class CMiddlewareDataFilterProxyModel final : public QDeepFilterProxyModel <nl> CMiddlewareDataFilterProxyModel ( QObject * parent ) ; <nl> <nl> / / QSortFilterProxyModel <nl> - virtual bool lessThan ( const QModelIndex & left , const QModelIndex & right ) const override ; <nl> + virtual bool lessThan ( QModelIndex const & left , QModelIndex const & right ) const override ; <nl> / / ~ QSortFilterProxyModel <nl> <nl> / / QDeepFilterProxyModel <nl> - virtual bool rowMatchesFilter ( int source_row , const QModelIndex & source_parent ) const override ; <nl> + virtual bool rowMatchesFilter ( int source_row , QModelIndex const & source_parent ) const override ; <nl> / / ~ QDeepFilterProxyModel <nl> <nl> void SetAllowedControlsMask ( uint allowedControlsMask ) ; <nl> - void SetHideConnected ( bool bHideConnected ) ; <nl> + void SetHideConnected ( bool const bHideConnected ) ; <nl> <nl> private : <nl> <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / MiddlewareDataWidget . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / MiddlewareDataWidget . cpp <nl> <nl> / / Copyright 2001 - 2016 Crytek GmbH / Crytek Group . All rights reserved . <nl> <nl> # include " StdAfx . h " <nl> - <nl> - # include " QtUtil . h " <nl> # include " MiddlewareDataWidget . h " <nl> + <nl> # include " IAudioSystemEditor . h " <nl> # include " AudioControlsEditorPlugin . h " <nl> # include " MiddlewareDataModel . h " <nl> # include " ImplementationManager . h " <nl> - # include " AdvancedTreeView . h " <nl> + # include " AudioTreeView . h " <nl> <nl> # include < CryIcon . h > <nl> # include < QSearchBox . h > <nl> - <nl> - / / Qt <nl> # include < QtUtil . h > <nl> - # include < QCheckBox > <nl> - # include < QHeaderView > <nl> - # include < QVBoxLayout > <nl> + <nl> + # include < QFontMetrics > <nl> # include < QHBoxLayout > <nl> + # include < QHeaderView > <nl> # include < QLabel > <nl> # include < QMenu > <nl> - # include < QFontMetrics > <nl> + # include < QToolButton > <nl> + # include < QVBoxLayout > <nl> <nl> + namespace ACE <nl> + { <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> class CElidedLabel final : public QLabel <nl> { <nl> public : <nl> class CElidedLabel final : public QLabel <nl> QString m_originalText ; <nl> } ; <nl> <nl> - namespace ACE <nl> - { <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CMiddlewareDataWidget : : CMiddlewareDataWidget ( ) <nl> - : m_pModelProxy ( new CMiddlewareDataFilterProxyModel ( this ) ) <nl> - , m_pModel ( new CMiddlewareDataModel ( ) ) <nl> + : m_pFilterProxyModel ( new CMiddlewareDataFilterProxyModel ( this ) ) <nl> + , m_pAssetsModel ( new CMiddlewareDataModel ( ) ) <nl> , m_pImplNameLabel ( nullptr ) <nl> { <nl> - setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Preferred ) ; <nl> + <nl> <nl> - m_pModelProxy - > setDynamicSortFilter ( true ) ; <nl> - m_pModelProxy - > setSourceModel ( m_pModel ) ; <nl> + m_pFilterProxyModel - > setDynamicSortFilter ( true ) ; <nl> + m_pFilterProxyModel - > setSourceModel ( m_pAssetsModel ) ; <nl> + <nl> + setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Preferred ) ; <nl> <nl> QVBoxLayout * pMainLayout = new QVBoxLayout ( this ) ; <nl> pMainLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ; <nl> CMiddlewareDataWidget : : CMiddlewareDataWidget ( ) <nl> m_pImplNameLabel - > SetLabelText ( QtUtil : : ToQString ( pAudioImpl - > GetName ( ) ) ) ; <nl> } <nl> <nl> - QHBoxLayout * pTopBarLayout = new QHBoxLayout ( ) ; <nl> + pMainLayout - > addWidget ( m_pImplNameLabel ) ; <nl> + <nl> + InitFilterWidgets ( pMainLayout ) ; <nl> + <nl> + m_pTreeView = new CAudioTreeView ( ) ; <nl> + m_pTreeView - > setEditTriggers ( QAbstractItemView : : NoEditTriggers ) ; <nl> + m_pTreeView - > setDragEnabled ( true ) ; <nl> + m_pTreeView - > setDragDropMode ( QAbstractItemView : : DragOnly ) ; <nl> + m_pTreeView - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ; <nl> + m_pTreeView - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ; <nl> + m_pTreeView - > setModel ( m_pFilterProxyModel ) ; <nl> + m_pTreeView - > sortByColumn ( 0 , Qt : : AscendingOrder ) ; <nl> + pMainLayout - > addWidget ( m_pTreeView ) ; <nl> + <nl> + QObject : : connect ( m_pTreeView , & CAudioTreeView : : customContextMenuRequested , this , & CMiddlewareDataWidget : : OnContextMenu ) ; <nl> + QObject : : connect ( m_pTreeView - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , m_pTreeView , & CAudioTreeView : : OnSelectionChanged ) ; <nl> + <nl> + CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > signalImplementationChanged . Connect ( [ & ] ( ) <nl> + { <nl> + IAudioSystemEditor * pAudioImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> + <nl> + if ( pAudioImpl ) <nl> + { <nl> + m_pImplNameLabel - > SetLabelText ( QtUtil : : ToQString ( pAudioImpl - > GetName ( ) ) ) ; <nl> + } <nl> + } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + CMiddlewareDataWidget : : ~ CMiddlewareDataWidget ( ) <nl> + { <nl> + CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > signalImplementationChanged . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + void CMiddlewareDataWidget : : InitFilterWidgets ( QVBoxLayout * pMainLayout ) <nl> + { <nl> + QHBoxLayout * pFilterLayout = new QHBoxLayout ( ) ; <nl> <nl> QSearchBox * pSearchBox = new QSearchBox ( ) ; <nl> - pSearchBox - > setToolTip ( tr ( " Show only middleware controls with this name " ) ) ; <nl> - connect ( pSearchBox , & QSearchBox : : textChanged , [ & ] ( QString const & filter ) <nl> + QObject : : connect ( pSearchBox , & QSearchBox : : textChanged , [ & ] ( QString const & filter ) <nl> { <nl> if ( m_filter ! = filter ) <nl> { <nl> CMiddlewareDataWidget : : CMiddlewareDataWidget ( ) <nl> } <nl> else if ( ! m_filter . isEmpty ( ) & & filter . isEmpty ( ) ) <nl> { <nl> - m_pModelProxy - > setFilterFixedString ( filter ) ; <nl> + m_pFilterProxyModel - > setFilterFixedString ( filter ) ; <nl> m_pTreeView - > collapseAll ( ) ; <nl> RestoreTreeViewStates ( ) ; <nl> } <nl> else if ( ! m_filter . isEmpty ( ) & & ! filter . isEmpty ( ) ) <nl> { <nl> - m_pModelProxy - > setFilterFixedString ( filter ) ; <nl> + m_pFilterProxyModel - > setFilterFixedString ( filter ) ; <nl> m_pTreeView - > expandAll ( ) ; <nl> } <nl> <nl> m_filter = filter ; <nl> } <nl> <nl> - m_pModelProxy - > setFilterFixedString ( filter ) ; <nl> + m_pFilterProxyModel - > setFilterFixedString ( filter ) ; <nl> } ) ; <nl> - <nl> - QCheckBox * pHideAssignedCheckbox = new QCheckBox ( ) ; <nl> - pHideAssignedCheckbox - > setText ( tr ( " Hide Assigned " ) ) ; <nl> - pHideAssignedCheckbox - > setToolTip ( tr ( " Hide or show assigned middleware controls " ) ) ; <nl> - connect ( pHideAssignedCheckbox , & QCheckBox : : clicked , [ & ] ( bool bHide ) <nl> + <nl> + pFilterLayout - > addWidget ( pSearchBox ) ; <nl> + <nl> + m_pHideAssignedButton = new QToolButton ( ) ; <nl> + m_pHideAssignedButton - > setIcon ( CryIcon ( " icons : General / Visibility_True . ico " ) ) ; <nl> + m_pHideAssignedButton - > setToolTip ( tr ( " Hide assigned middleware data " ) ) ; <nl> + m_pHideAssignedButton - > setCheckable ( true ) ; <nl> + m_pHideAssignedButton - > setMaximumSize ( QSize ( 20 , 20 ) ) ; <nl> + QObject : : connect ( m_pHideAssignedButton , & QToolButton : : toggled , [ & ] ( bool const bChecked ) <nl> { <nl> - if ( bHide ) <nl> + if ( bChecked ) <nl> { <nl> - m_pTreeView - > BackupExpanded ( ) ; <nl> - m_pModelProxy - > SetHideConnected ( bHide ) ; <nl> + BackupTreeViewStates ( ) ; <nl> + m_pFilterProxyModel - > SetHideConnected ( bChecked ) ; <nl> + m_pHideAssignedButton - > setIcon ( CryIcon ( " icons : General / Visibility_False . ico " ) ) ; <nl> + m_pHideAssignedButton - > setToolTip ( tr ( " Show all middleware data " ) ) ; <nl> } <nl> else <nl> { <nl> - m_pModelProxy - > SetHideConnected ( bHide ) ; <nl> - m_pTreeView - > RestoreExpanded ( ) ; <nl> + m_pFilterProxyModel - > SetHideConnected ( bChecked ) ; <nl> + RestoreTreeViewStates ( ) ; <nl> + m_pHideAssignedButton - > setIcon ( CryIcon ( " icons : General / Visibility_True . ico " ) ) ; <nl> + m_pHideAssignedButton - > setToolTip ( tr ( " Hide assigned middleware data " ) ) ; <nl> } <nl> } ) ; <nl> <nl> - pTopBarLayout - > addWidget ( pSearchBox ) ; <nl> - pTopBarLayout - > addWidget ( pHideAssignedCheckbox ) ; <nl> - <nl> - m_pTreeView = new CAdvancedTreeView ( ) ; <nl> - m_pTreeView - > header ( ) - > setVisible ( false ) ; <nl> - m_pTreeView - > setDragEnabled ( true ) ; <nl> - m_pTreeView - > setDragDropMode ( QAbstractItemView : : DragOnly ) ; <nl> - m_pTreeView - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ; <nl> - m_pTreeView - > setSortingEnabled ( true ) ; <nl> - m_pTreeView - > sortByColumn ( 0 , Qt : : AscendingOrder ) ; <nl> - m_pTreeView - > setModel ( m_pModelProxy ) ; <nl> - m_pTreeView - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ; <nl> - connect ( m_pTreeView , & CAdvancedTreeView : : customContextMenuRequested , this , & CMiddlewareDataWidget : : OnContextMenu ) ; <nl> - connect ( m_pTreeView - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , m_pTreeView , & CAdvancedTreeView : : OnSelectionChanged ) ; <nl> - <nl> - pMainLayout - > addWidget ( m_pImplNameLabel ) ; <nl> - pMainLayout - > addLayout ( pTopBarLayout ) ; <nl> - pMainLayout - > addWidget ( m_pTreeView ) ; <nl> - <nl> - / / Update the middleware name label . <nl> - / / Note the ' this ' ptr being passed as a context variable so that Qt can disconnect this lambda when the object is destroyed ( ie . the ACE is closed ) . <nl> - CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > signalImplementationChanged . Connect ( [ & ] ( ) <nl> - { <nl> - IAudioSystemEditor * pAudioImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> + pFilterLayout - > addWidget ( m_pHideAssignedButton ) ; <nl> <nl> - if ( pAudioImpl ) <nl> - { <nl> - m_pImplNameLabel - > SetLabelText ( QtUtil : : ToQString ( pAudioImpl - > GetName ( ) ) ) ; <nl> - } <nl> - } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CMiddlewareDataWidget : : ~ CMiddlewareDataWidget ( ) <nl> - { <nl> - CAudioControlsEditorPlugin : : GetImplementationManger ( ) - > signalImplementationChanged . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + pMainLayout - > addLayout ( pFilterLayout ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CMiddlewareDataWidget : : SetAllowedControls ( EItemType type , bool bAllowed ) <nl> + void CMiddlewareDataWidget : : SetAllowedControls ( EItemType const type , bool const bAllowed ) <nl> { <nl> - const ACE : : IAudioSystemEditor * pAudioSystemEditorImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> + const IAudioSystemEditor * pAudioSystemEditorImpl = CAudioControlsEditorPlugin : : GetAudioSystemEditorImpl ( ) ; <nl> <nl> if ( pAudioSystemEditorImpl ) <nl> { <nl> - m_allowedATLTypes [ type ] = bAllowed ; <nl> + m_allowedATLTypes [ static_cast < int > ( type ) ] = bAllowed ; <nl> uint mask = 0 ; <nl> + int const numTypes = static_cast < int > ( EItemType : : NumTypes ) ; <nl> <nl> - for ( int i = 0 ; i < EItemType : : eItemType_NumTypes ; + + i ) <nl> + for ( int i = 0 ; i < numTypes ; + + i ) <nl> { <nl> if ( m_allowedATLTypes [ i ] ) <nl> { <nl> void CMiddlewareDataWidget : : SetAllowedControls ( EItemType type , bool bAllowed ) <nl> } <nl> } <nl> <nl> - m_pModelProxy - > SetAllowedControlsMask ( mask ) ; <nl> + m_pFilterProxyModel - > SetAllowedControlsMask ( mask ) ; <nl> } <nl> } <nl> <nl> void CMiddlewareDataWidget : : OnContextMenu ( QPoint const & pos ) const <nl> pContextMenu - > addAction ( tr ( " Expand All " ) , [ & ] ( ) { m_pTreeView - > expandAll ( ) ; } ) ; <nl> pContextMenu - > addAction ( tr ( " Collapse All " ) , [ & ] ( ) { m_pTreeView - > collapseAll ( ) ; } ) ; <nl> <nl> - pContextMenu - > exec ( m_pTreeView - > mapToGlobal ( pos ) ) ; <nl> + pContextMenu - > exec ( QCursor : : pos ( ) ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CMiddlewareDataWidget : : Reset ( ) <nl> { <nl> - m_pModel - > Reset ( ) ; <nl> - m_pModelProxy - > invalidate ( ) ; <nl> + m_pAssetsModel - > Reset ( ) ; <nl> + m_pFilterProxyModel - > invalidate ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / MiddlewareDataWidget . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / MiddlewareDataWidget . h <nl> <nl> <nl> # pragma once <nl> <nl> - # include < QFrame > <nl> + # include < QWidget > <nl> # include < ACETypes . h > <nl> <nl> - class CElidedLabel ; <nl> + class QToolButton ; <nl> + class QVBoxLayout ; <nl> <nl> namespace ACE <nl> { <nl> class CMiddlewareDataFilterProxyModel ; <nl> class CMiddlewareDataModel ; <nl> - class CAdvancedTreeView ; <nl> + class CAudioTreeView ; <nl> + class CElidedLabel ; <nl> <nl> - class CMiddlewareDataWidget final : public QFrame <nl> + class CMiddlewareDataWidget final : public QWidget <nl> { <nl> Q_OBJECT <nl> <nl> class CMiddlewareDataWidget final : public QFrame <nl> CMiddlewareDataWidget ( ) ; <nl> virtual ~ CMiddlewareDataWidget ( ) override ; <nl> <nl> - void SetAllowedControls ( EItemType type , bool bAllowed ) ; <nl> + void SetAllowedControls ( EItemType const type , bool const bAllowed ) ; <nl> void Reset ( ) ; <nl> void BackupTreeViewStates ( ) ; <nl> void RestoreTreeViewStates ( ) ; <nl> private slots : <nl> <nl> private : <nl> <nl> - bool m_allowedATLTypes [ EItemType : : eItemType_NumTypes ] ; <nl> - CMiddlewareDataFilterProxyModel * m_pModelProxy ; <nl> - CMiddlewareDataModel * m_pModel ; <nl> - CElidedLabel * m_pImplNameLabel ; <nl> - CAdvancedTreeView * m_pTreeView ; <nl> - QString m_filter ; <nl> + void InitFilterWidgets ( QVBoxLayout * pMainLayout ) ; <nl> + <nl> + bool m_allowedATLTypes [ static_cast < int > ( EItemType : : NumTypes ) ] ; / / Replace this . Possibly with a QList . <nl> + CMiddlewareDataFilterProxyModel * m_pFilterProxyModel ; <nl> + CMiddlewareDataModel * m_pAssetsModel ; <nl> + CElidedLabel * m_pImplNameLabel ; <nl> + QToolButton * m_pHideAssignedButton ; <nl> + CAudioTreeView * m_pTreeView ; <nl> + QString m_filter ; <nl> } ; <nl> } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / PreferencesDialog . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / PreferencesDialog . cpp <nl> CPreferencesDialog : : CPreferencesDialog ( QWidget * pParent ) <nl> <nl> QGridLayout * pLayout = new QGridLayout ( this ) ; <nl> <nl> - pLayout - > addWidget ( new QLabel ( tr ( " Audio Middleware " ) + " : " ) , 0 , 0 , Qt : : AlignLeft | Qt : : AlignVCenter ) ; <nl> - pLayout - > addWidget ( new QLabel ( QtUtil : : ToQString ( pAudioSystem - > GetName ( ) ) ) , 0 , 1 , Qt : : AlignLeft | Qt : : AlignVCenter ) ; <nl> + Qt : : Alignment const labelAlignment = static_cast < Qt : : Alignment > ( Qt : : AlignLeft | Qt : : AlignVCenter ) ; <nl> <nl> - pLayout - > addWidget ( new QLabel ( tr ( " Sound Banks Path " ) + " : " ) , 1 , 0 , Qt : : AlignLeft | Qt : : AlignVCenter ) ; <nl> + pLayout - > addWidget ( new QLabel ( tr ( " Audio Middleware " ) + " : " ) , 0 , 0 , labelAlignment ) ; <nl> + pLayout - > addWidget ( new QLabel ( QtUtil : : ToQString ( pAudioSystem - > GetName ( ) ) ) , 0 , 1 , labelAlignment ) ; <nl> + <nl> + pLayout - > addWidget ( new QLabel ( tr ( " Sound Banks Path " ) + " : " ) , 1 , 0 , labelAlignment ) ; <nl> pLayout - > addWidget ( new QLabel ( pSettings - > GetSoundBanksPath ( ) ) , 1 , 1 ) ; <nl> <nl> - pLayout - > addWidget ( new QLabel ( tr ( " Project Path " ) + " : " ) , 2 , 0 , Qt : : AlignLeft | Qt : : AlignVCenter ) ; <nl> + pLayout - > addWidget ( new QLabel ( tr ( " Project Path " ) + " : " ) , 2 , 0 , labelAlignment ) ; <nl> <nl> QHBoxLayout * pProjectPathLayout = new QHBoxLayout ( this ) ; <nl> m_projectPath = pSettings - > GetProjectPath ( ) ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / PropertiesWidget . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / PropertiesWidget . cpp <nl> <nl> # include " StdAfx . h " <nl> # include " PropertiesWidget . h " <nl> <nl> - # include < QVBoxLayout > <nl> - # include < QLabel > <nl> - # include < Serialization / QPropertyTree / QPropertyTree . h > <nl> + # include " AudioAssetsManager . h " <nl> + # include " ConnectionsWidget . h " <nl> + # include " SystemControlsEditorIcons . h " <nl> + <nl> # include < ACETypes . h > <nl> # include < IEditor . h > <nl> # include < QtUtil . h > <nl> - # include < QString > <nl> + # include < Serialization / QPropertyTree / QPropertyTree . h > <nl> <nl> - # include " SystemControlsEditorIcons . h " <nl> - # include " ConnectionsWidget . h " <nl> - # include " AudioAssetsManager . h " <nl> + # include < QLabel > <nl> + # include < QString > <nl> + # include < QVBoxLayout > <nl> <nl> using namespace QtUtil ; <nl> <nl> namespace ACE <nl> CPropertiesWidget : : CPropertiesWidget ( CAudioAssetsManager * pAssetsManager ) <nl> : m_pAssetsManager ( pAssetsManager ) <nl> { <nl> - assert ( m_pAssetsManager ) ; <nl> - setWindowTitle ( tr ( " Inspector Panel " ) ) ; <nl> + CRY_ASSERT ( m_pAssetsManager ) ; <nl> + <nl> setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Preferred ) ; <nl> <nl> QVBoxLayout * pMainLayout = new QVBoxLayout ( this ) ; <nl> CPropertiesWidget : : CPropertiesWidget ( CAudioAssetsManager * pAssetsManager ) <nl> <nl> m_pPropertyTree = new QPropertyTree ( ) ; <nl> m_pPropertyTree - > setSizeToContent ( true ) ; <nl> + pMainLayout - > addWidget ( m_pPropertyTree ) ; <nl> <nl> m_pUsageHint = std : : make_unique < QString > ( tr ( " Select an audio control from the left pane to see its properties ! " ) ) ; <nl> <nl> m_pConnectionsLabel = new QLabel ( * m_pUsageHint ) ; <nl> - m_pConnectionsLabel - > setObjectName ( " ConnectionsTitle " ) ; <nl> m_pConnectionsLabel - > setAlignment ( Qt : : AlignCenter ) ; <nl> m_pConnectionsLabel - > setWordWrap ( true ) ; <nl> - <nl> - m_pConnectionList = new CConnectionsWidget ( ) ; <nl> - m_pConnectionList - > Init ( ) ; <nl> - <nl> - pMainLayout - > addWidget ( m_pPropertyTree ) ; <nl> pMainLayout - > addWidget ( m_pConnectionsLabel ) ; <nl> - pMainLayout - > addWidget ( m_pConnectionList ) ; <nl> + <nl> + m_pConnectionsWidget = new CConnectionsWidget ( ) ; <nl> + pMainLayout - > addWidget ( m_pConnectionsWidget ) ; <nl> <nl> auto revertFunction = [ & ] ( ) <nl> { <nl> CPropertiesWidget : : CPropertiesWidget ( CAudioAssetsManager * pAssetsManager ) <nl> pAssetsManager - > signalItemRemoved . Connect ( revertFunction , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> pAssetsManager - > signalControlModified . Connect ( revertFunction , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> <nl> - Reload ( ) ; <nl> - <nl> - connect ( m_pPropertyTree , & QPropertyTree : : signalAboutToSerialize , [ & ] ( ) <nl> - { <nl> - m_bSupressUpdates = true ; <nl> - } ) ; <nl> - <nl> - connect ( m_pPropertyTree , & QPropertyTree : : signalSerialized , [ & ] ( ) <nl> - { <nl> - m_bSupressUpdates = false ; <nl> - } ) ; <nl> + connect ( m_pPropertyTree , & QPropertyTree : : signalAboutToSerialize , [ & ] ( ) { m_bSupressUpdates = true ; } ) ; <nl> + connect ( m_pPropertyTree , & QPropertyTree : : signalSerialized , [ & ] ( ) { m_bSupressUpdates = false ; } ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CPropertiesWidget : : ~ CPropertiesWidget ( ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CPropertiesWidget : : Reload ( ) <nl> { <nl> - m_pConnectionList - > Reload ( ) ; <nl> + m_pConnectionsWidget - > Reload ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CPropertiesWidget : : SetSelectedControls ( const std : : vector < CAudioControl * > & selectedControls ) <nl> + void CPropertiesWidget : : SetSelectedControls ( std : : vector < CAudioControl * > const & selectedControls ) <nl> { <nl> / / Update property tree <nl> m_pPropertyTree - > detach ( ) ; <nl> void CPropertiesWidget : : SetSelectedControls ( const std : : vector < CAudioControl * > & s <nl> if ( selectedControls . size ( ) = = 1 ) <nl> { <nl> CAudioControl * pControl = selectedControls [ 0 ] ; <nl> - if ( pControl - > GetType ( ) ! = eItemType_Switch ) <nl> + <nl> + if ( pControl - > GetType ( ) ! = EItemType : : Switch ) <nl> { <nl> - m_pConnectionList - > SetControl ( pControl ) ; <nl> - m_pConnectionList - > setHidden ( false ) ; <nl> + m_pConnectionsWidget - > SetControl ( pControl ) ; <nl> + m_pConnectionsWidget - > setHidden ( false ) ; <nl> m_pConnectionsLabel - > setAlignment ( Qt : : AlignLeft ) ; <nl> m_pConnectionsLabel - > setText ( tr ( " Connections " ) ) ; <nl> } <nl> else <nl> { <nl> - m_pConnectionList - > setHidden ( true ) ; <nl> + m_pConnectionsWidget - > setHidden ( true ) ; <nl> m_pConnectionsLabel - > setAlignment ( Qt : : AlignCenter ) ; <nl> - m_pConnectionsLabel - > setText ( tr ( " Select a switch state to see its properties ! " ) ) ; <nl> + m_pConnectionsLabel - > setText ( tr ( " Select a switch state to see its connections ! " ) ) ; <nl> } <nl> } <nl> else <nl> { <nl> - m_pConnectionList - > setHidden ( true ) ; <nl> - m_pConnectionList - > SetControl ( nullptr ) ; <nl> + m_pConnectionsWidget - > setHidden ( true ) ; <nl> + m_pConnectionsWidget - > SetControl ( nullptr ) ; <nl> m_pConnectionsLabel - > setAlignment ( Qt : : AlignCenter ) ; <nl> m_pConnectionsLabel - > setText ( * m_pUsageHint ) ; <nl> } <nl> void CPropertiesWidget : : SetSelectedControls ( const std : : vector < CAudioControl * > & s <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CPropertiesWidget : : BackupTreeViewStates ( ) <nl> { <nl> - m_pConnectionList - > BackupTreeViewStates ( ) ; <nl> + m_pConnectionsWidget - > BackupTreeViewStates ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CPropertiesWidget : : RestoreTreeViewStates ( ) <nl> { <nl> - m_pConnectionList - > RestoreTreeViewStates ( ) ; <nl> + m_pConnectionsWidget - > RestoreTreeViewStates ( ) ; <nl> } <nl> } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / PropertiesWidget . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / PropertiesWidget . h <nl> <nl> <nl> # pragma once <nl> <nl> - # include < QFrame > <nl> + # include < QWidget > <nl> <nl> class QPropertyTree ; <nl> class QLabel ; <nl> class CAudioAssetsManager ; <nl> class IAudioSystemItem ; <nl> class CAudioControl ; <nl> <nl> - class CPropertiesWidget final : public QFrame <nl> + class CPropertiesWidget final : public QWidget <nl> { <nl> Q_OBJECT <nl> + <nl> public : <nl> <nl> explicit CPropertiesWidget ( CAudioAssetsManager * pAssetsManager ) ; <nl> class CPropertiesWidget final : public QFrame <nl> <nl> public slots : <nl> <nl> - void SetSelectedControls ( const std : : vector < CAudioControl * > & selectedControls ) ; <nl> + void SetSelectedControls ( std : : vector < CAudioControl * > const & selectedControls ) ; <nl> <nl> private : <nl> <nl> CAudioAssetsManager * m_pAssetsManager ; <nl> - CConnectionsWidget * m_pConnectionList ; <nl> + CConnectionsWidget * m_pConnectionsWidget ; <nl> QPropertyTree * m_pPropertyTree ; <nl> QLabel * m_pConnectionsLabel ; <nl> std : : unique_ptr < QString > m_pUsageHint ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / ResourceSelectorDialog . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / ResourceSelectorDialog . cpp <nl> <nl> # include < QAdvancedTreeView . h > <nl> # include < QSearchBox . h > <nl> # include < ProxyModels / MountingProxyModel . h > <nl> + # include < ProxyModels / DeepFilterProxyModel . h > <nl> <nl> # include < QDialogButtonBox > <nl> # include < QVBoxLayout > <nl> <nl> namespace ACE <nl> { <nl> string CResourceSelectorDialog : : s_previousControlName = " " ; <nl> - EItemType CResourceSelectorDialog : : s_previousControlType = eItemType_Invalid ; <nl> + EItemType CResourceSelectorDialog : : s_previousControlType = EItemType : : Invalid ; <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CResourceSelectorDialog : : CResourceSelectorDialog ( QWidget * pParent , EItemType const eType ) <nl> CResourceSelectorDialog : : CResourceSelectorDialog ( QWidget * pParent , EItemType con <nl> setWindowModality ( Qt : : ApplicationModal ) ; <nl> <nl> m_pAssetsManager = CAudioControlsEditorPlugin : : GetAssetsManager ( ) ; <nl> - m_pFilterProxyModel = new CResourceFilterProxyModel ( ) ; <nl> + m_pFilterProxyModel = new QDeepFilterProxyModel ( ) ; <nl> m_pAssetsModel = new CResourceControlModel ( m_pAssetsManager ) ; <nl> <nl> m_pMountingProxyModel = new CMountingProxyModel ( WrapMemberFunction ( this , & CResourceSelectorDialog : : CreateLibraryModelFromIndex ) ) ; <nl> CResourceSelectorDialog : : CResourceSelectorDialog ( QWidget * pParent , EItemType con <nl> QSearchBox * pSearchBox = new QSearchBox ( ) ; <nl> pWindowLayout - > addWidget ( pSearchBox ) ; <nl> <nl> - m_pControlsTree = new QAdvancedTreeView ( ) ; <nl> - m_pControlsTree - > setAutoScroll ( true ) ; <nl> - m_pControlsTree - > setDragEnabled ( false ) ; <nl> - m_pControlsTree - > setDragDropMode ( QAbstractItemView : : NoDragDrop ) ; <nl> - m_pControlsTree - > setDefaultDropAction ( Qt : : IgnoreAction ) ; <nl> - m_pControlsTree - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ; <nl> - m_pControlsTree - > setEditTriggers ( QAbstractItemView : : NoEditTriggers ) ; <nl> - m_pControlsTree - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ; <nl> - m_pControlsTree - > setModel ( m_pFilterProxyModel ) ; <nl> - m_pControlsTree - > installEventFilter ( this ) ; <nl> - pWindowLayout - > addWidget ( m_pControlsTree ) ; <nl> + m_pTreeView = new QAdvancedTreeView ( ) ; <nl> + m_pTreeView - > setEditTriggers ( QAbstractItemView : : NoEditTriggers ) ; <nl> + m_pTreeView - > setDragEnabled ( false ) ; <nl> + m_pTreeView - > setDragDropMode ( QAbstractItemView : : NoDragDrop ) ; <nl> + m_pTreeView - > setDefaultDropAction ( Qt : : IgnoreAction ) ; <nl> + m_pTreeView - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ; <nl> + m_pTreeView - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ; <nl> + m_pTreeView - > setModel ( m_pFilterProxyModel ) ; <nl> + m_pTreeView - > sortByColumn ( 0 , Qt : : AscendingOrder ) ; <nl> + m_pTreeView - > installEventFilter ( this ) ; <nl> + pWindowLayout - > addWidget ( m_pTreeView ) ; <nl> <nl> m_pDialogButtons = new QDialogButtonBox ( ) ; <nl> m_pDialogButtons - > setStandardButtons ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ; <nl> CResourceSelectorDialog : : CResourceSelectorDialog ( QWidget * pParent , EItemType con <nl> pWindowLayout - > addWidget ( m_pDialogButtons ) ; <nl> <nl> QObject : : connect ( pSearchBox , & QSearchBox : : textChanged , this , & CResourceSelectorDialog : : SetTextFilter ) ; <nl> - <nl> - QObject : : connect ( m_pControlsTree , & QAdvancedTreeView : : customContextMenuRequested , this , & CResourceSelectorDialog : : OnContextMenu ) ; <nl> - QObject : : connect ( m_pControlsTree , & QAdvancedTreeView : : doubleClicked , this , & CResourceSelectorDialog : : ItemDoubleClicked ) ; <nl> - QObject : : connect ( m_pControlsTree - > header ( ) , & QHeaderView : : sortIndicatorChanged , [ & ] ( ) <nl> - { <nl> - QModelIndex const & currentIndex = m_pControlsTree - > currentIndex ( ) ; <nl> - <nl> - if ( currentIndex . isValid ( ) ) <nl> - { <nl> - m_pControlsTree - > scrollTo ( currentIndex ) ; <nl> - } <nl> - } ) ; <nl> - <nl> - QObject : : connect ( m_pControlsTree - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , this , & CResourceSelectorDialog : : UpdateSelectedControl ) ; <nl> - QObject : : connect ( m_pControlsTree - > selectionModel ( ) , & QItemSelectionModel : : currentChanged , this , & CResourceSelectorDialog : : StopTrigger ) ; <nl> - <nl> + QObject : : connect ( m_pTreeView , & QAdvancedTreeView : : customContextMenuRequested , this , & CResourceSelectorDialog : : OnContextMenu ) ; <nl> + QObject : : connect ( m_pTreeView , & QAdvancedTreeView : : doubleClicked , this , & CResourceSelectorDialog : : ItemDoubleClicked ) ; <nl> + QObject : : connect ( m_pTreeView - > header ( ) , & QHeaderView : : sortIndicatorChanged , [ & ] ( ) { m_pTreeView - > scrollTo ( m_pTreeView - > currentIndex ( ) ) ; } ) ; <nl> + QObject : : connect ( m_pTreeView - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , this , & CResourceSelectorDialog : : UpdateSelectedControl ) ; <nl> + QObject : : connect ( m_pTreeView - > selectionModel ( ) , & QItemSelectionModel : : currentChanged , this , & CResourceSelectorDialog : : StopTrigger ) ; <nl> QObject : : connect ( m_pDialogButtons , & QDialogButtonBox : : accepted , this , & CResourceSelectorDialog : : accept ) ; <nl> QObject : : connect ( m_pDialogButtons , & QDialogButtonBox : : rejected , this , & CResourceSelectorDialog : : reject ) ; <nl> <nl> const char * CResourceSelectorDialog : : ChooseItem ( const char * szCurrentValue ) <nl> <nl> if ( index . isValid ( ) ) <nl> { <nl> - m_pControlsTree - > setCurrentIndex ( index ) ; <nl> + m_pTreeView - > setCurrentIndex ( index ) ; <nl> } <nl> } <nl> <nl> void CResourceSelectorDialog : : UpdateSelectedControl ( ) <nl> { <nl> if ( m_pAssetsManager ) <nl> { <nl> - QModelIndexList const indexes = m_pControlsTree - > selectionModel ( ) - > selectedIndexes ( ) ; <nl> + QModelIndexList const indexes = m_pTreeView - > selectionModel ( ) - > selectedIndexes ( ) ; <nl> <nl> if ( ! indexes . empty ( ) ) <nl> { <nl> void CResourceSelectorDialog : : UpdateSelectedControl ( ) <nl> s_previousControlName = pAsset - > GetName ( ) ; <nl> } <nl> <nl> - m_bSelectionIsValid = ( pAsset & & ( pAsset - > GetType ( ) ! = eItemType_Folder ) & & ( pAsset & & pAsset - > GetType ( ) ! = eItemType_Library ) ) ; <nl> + m_bSelectionIsValid = ( pAsset & & ( pAsset - > GetType ( ) ! = EItemType : : Folder ) & & ( pAsset & & pAsset - > GetType ( ) ! = EItemType : : Library ) ) ; <nl> m_pDialogButtons - > button ( QDialogButtonBox : : Ok ) - > setEnabled ( m_bSelectionIsValid ) ; <nl> } <nl> } <nl> void CResourceSelectorDialog : : SetTextFilter ( QString const & filter ) <nl> { <nl> if ( m_sFilter . isEmpty ( ) & & ! filter . isEmpty ( ) ) <nl> { <nl> - m_pControlsTree - > BackupExpanded ( ) ; <nl> - m_pControlsTree - > expandAll ( ) ; <nl> + m_pTreeView - > BackupExpanded ( ) ; <nl> + m_pTreeView - > expandAll ( ) ; <nl> } <nl> else if ( ! m_sFilter . isEmpty ( ) & & filter . isEmpty ( ) ) <nl> { <nl> - m_pControlsTree - > collapseAll ( ) ; <nl> - m_pControlsTree - > RestoreExpanded ( ) ; <nl> + m_pTreeView - > collapseAll ( ) ; <nl> + m_pTreeView - > RestoreExpanded ( ) ; <nl> } <nl> <nl> m_sFilter = filter ; <nl> ApplyFilter ( ) ; <nl> <nl> - QModelIndex const & currentIndex = m_pControlsTree - > currentIndex ( ) ; <nl> + QModelIndex const & currentIndex = m_pTreeView - > currentIndex ( ) ; <nl> <nl> if ( currentIndex . isValid ( ) ) <nl> { <nl> - m_pControlsTree - > scrollTo ( currentIndex ) ; <nl> + m_pTreeView - > scrollTo ( currentIndex ) ; <nl> } <nl> } <nl> } <nl> bool CResourceSelectorDialog : : ApplyFilter ( QModelIndex const & parent ) <nl> <nl> if ( bChildValid | | ( pAsset & & pAsset - > GetType ( ) = = m_eType & & IsValid ( parent ) ) ) <nl> { <nl> - m_pControlsTree - > setRowHidden ( parent . row ( ) , parent . parent ( ) , false ) ; <nl> + m_pTreeView - > setRowHidden ( parent . row ( ) , parent . parent ( ) , false ) ; <nl> return true ; <nl> } <nl> else <nl> { <nl> - m_pControlsTree - > setRowHidden ( parent . row ( ) , parent . parent ( ) , true ) ; <nl> + m_pTreeView - > setRowHidden ( parent . row ( ) , parent . parent ( ) , true ) ; <nl> <nl> } <nl> } <nl> bool CResourceSelectorDialog : : eventFilter ( QObject * pObject , QEvent * pEvent ) <nl> <nl> if ( pKeyEvent & & ( pKeyEvent - > key ( ) = = Qt : : Key_Space ) ) <nl> { <nl> - QModelIndex const & index = m_pControlsTree - > currentIndex ( ) ; <nl> + QModelIndex const & index = m_pTreeView - > currentIndex ( ) ; <nl> <nl> if ( index . isValid ( ) ) <nl> { <nl> CAudioAsset * const pAsset = AudioModelUtils : : GetAssetFromIndex ( index ) ; <nl> <nl> - if ( pAsset & & ( pAsset - > GetType ( ) = = eItemType_Trigger ) ) <nl> + if ( pAsset & & ( pAsset - > GetType ( ) = = EItemType : : Trigger ) ) <nl> { <nl> CAudioControlsEditorPlugin : : ExecuteTrigger ( pAsset - > GetName ( ) ) ; <nl> } <nl> void CResourceSelectorDialog : : ItemDoubleClicked ( QModelIndex const & modelIndex ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CResourceSelectorDialog : : OnContextMenu ( QPoint const & pos ) <nl> { <nl> - QModelIndex const & index = m_pControlsTree - > currentIndex ( ) ; <nl> + QModelIndex const & index = m_pTreeView - > currentIndex ( ) ; <nl> <nl> if ( index . isValid ( ) ) <nl> { <nl> CAudioAsset * const pAsset = AudioModelUtils : : GetAssetFromIndex ( index ) ; <nl> <nl> - if ( pAsset & & ( pAsset - > GetType ( ) = = eItemType_Trigger ) ) <nl> + if ( pAsset & & ( pAsset - > GetType ( ) = = EItemType : : Trigger ) ) <nl> { <nl> QMenu * pContextMenu = new QMenu ( ) ; <nl> <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / ResourceSelectorDialog . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / ResourceSelectorDialog . h <nl> namespace ACE <nl> class CAudioAssetsManager ; <nl> class CResourceControlModel ; <nl> class CResourceLibraryModel ; <nl> - class CResourceFilterProxyModel ; <nl> <nl> class CResourceSelectorDialog final : public CEditorDialog <nl> { <nl> private slots : <nl> <nl> static string s_previousControlName ; <nl> static EItemType s_previousControlType ; <nl> - QAdvancedTreeView * m_pControlsTree ; <nl> + QAdvancedTreeView * m_pTreeView ; <nl> QDialogButtonBox * m_pDialogButtons ; <nl> <nl> CAudioAssetsManager * m_pAssetsManager ; <nl> - CResourceFilterProxyModel * m_pFilterProxyModel ; <nl> + QDeepFilterProxyModel * m_pFilterProxyModel ; <nl> CResourceControlModel * m_pAssetsModel ; <nl> CMountingProxyModel * m_pMountingProxyModel ; <nl> std : : vector < CResourceLibraryModel * > m_libraryModels ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / ResourceSelectorModel . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / ResourceSelectorModel . cpp <nl> <nl> / / Copyright 2001 - 2016 Crytek GmbH / Crytek Group . All rights reserved . <nl> <nl> # include " StdAfx . h " <nl> - # include " AudioAssets . h " <nl> # include " ResourceSelectorModel . h " <nl> + <nl> + # include " AudioAssets . h " <nl> # include " SystemControlsEditorIcons . h " <nl> <nl> # include < QtUtil . h > <nl> <nl> namespace ACE <nl> { <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - bool CResourceFilterProxyModel : : lessThan ( QModelIndex const & left , QModelIndex const & right ) const <nl> - { <nl> - uint eLeftType = sourceModel ( ) - > data ( left , eDataRole_ItemType ) . toUInt ( ) ; <nl> - uint eRightType = sourceModel ( ) - > data ( right , eDataRole_ItemType ) . toUInt ( ) ; <nl> - <nl> - if ( eLeftType ! = eRightType ) <nl> - { <nl> - return eLeftType > eRightType ; <nl> - } <nl> - <nl> - return left . data ( Qt : : DisplayRole ) > right . data ( Qt : : DisplayRole ) ; <nl> - } <nl> - <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> QVariant CResourceControlModel : : data ( QModelIndex const & index , int role ) const <nl> { <nl> QVariant CResourceControlModel : : data ( QModelIndex const & index , int role ) const <nl> break ; <nl> <nl> case Qt : : DecorationRole : <nl> - return GetItemTypeIcon ( EItemType : : eItemType_Library ) ; <nl> + return GetItemTypeIcon ( EItemType : : Library ) ; <nl> break ; <nl> <nl> - case EDataRole : : eDataRole_ItemType : <nl> - return EItemType : : eItemType_Library ; <nl> + case static_cast < int > ( EDataRole : : ItemType ) : <nl> + return static_cast < int > ( EItemType : : Library ) ; <nl> break ; <nl> <nl> - case EDataRole : : eDataRole_InternalPointer : <nl> + case static_cast < int > ( EDataRole : : InternalPointer ) : <nl> return reinterpret_cast < intptr_t > ( pLibrary ) ; <nl> break ; <nl> } <nl> QVariant CResourceLibraryModel : : data ( QModelIndex const & index , int role ) const <nl> return GetItemTypeIcon ( itemType ) ; <nl> break ; <nl> <nl> - case EDataRole : : eDataRole_ItemType : <nl> - return itemType ; <nl> + case static_cast < int > ( EDataRole : : ItemType ) : <nl> + return static_cast < int > ( itemType ) ; <nl> break ; <nl> <nl> - case EDataRole : : eDataRole_InternalPointer : <nl> + case static_cast < int > ( EDataRole : : InternalPointer ) : <nl> return reinterpret_cast < intptr_t > ( pItem ) ; <nl> break ; <nl> } <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / ResourceSelectorModel . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / ResourceSelectorModel . h <nl> <nl> <nl> # include " SystemControlsModel . h " <nl> <nl> - # include < ProxyModels / DeepFilterProxyModel . h > <nl> - <nl> namespace ACE <nl> { <nl> class CAudioLibrary ; <nl> class CAudioAssetsManager ; <nl> <nl> - class CResourceFilterProxyModel final : public QDeepFilterProxyModel <nl> - { <nl> - public : <nl> - <nl> - CResourceFilterProxyModel ( ) = default ; <nl> - <nl> - protected : <nl> - <nl> - bool lessThan ( QModelIndex const & left , QModelIndex const & right ) const ; <nl> - } ; <nl> - <nl> class CResourceControlModel final : public CSystemControlsModel <nl> { <nl> public : <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / ResourceSelectors . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / ResourceSelectors . cpp <nl> namespace <nl> dll_string ShowSelectDialog ( const SResourceSelectorContext & context , const char * szPreviousValue , const EItemType controlType ) <nl> { <nl> CAudioAssetsManager * pAssetsManager = CAudioControlsEditorPlugin : : GetAssetsManager ( ) ; <nl> - assert ( pAssetsManager ) ; <nl> + CRY_ASSERT ( pAssetsManager ) ; <nl> <nl> QParentWndWidget parent ( context . parentWindow ) ; <nl> parent . center ( ) ; <nl> dll_string ShowSelectDialog ( const SResourceSelectorContext & context , const char * <nl> <nl> dll_string AudioTriggerSelector ( const SResourceSelectorContext & context , const char * szPreviousValue ) <nl> { <nl> - return ShowSelectDialog ( context , szPreviousValue , eItemType_Trigger ) ; <nl> + return ShowSelectDialog ( context , szPreviousValue , EItemType : : Trigger ) ; <nl> } <nl> <nl> dll_string AudioSwitchSelector ( const SResourceSelectorContext & context , const char * szPreviousValue ) <nl> { <nl> - return ShowSelectDialog ( context , szPreviousValue , eItemType_Switch ) ; <nl> + return ShowSelectDialog ( context , szPreviousValue , EItemType : : Switch ) ; <nl> } <nl> <nl> dll_string AudioSwitchStateSelector ( const SResourceSelectorContext & context , const char * szPreviousValue ) <nl> { <nl> - return ShowSelectDialog ( context , szPreviousValue , eItemType_State ) ; <nl> + return ShowSelectDialog ( context , szPreviousValue , EItemType : : State ) ; <nl> } <nl> <nl> dll_string AudioParameterSelector ( const SResourceSelectorContext & context , const char * szPreviousValue ) <nl> { <nl> - return ShowSelectDialog ( context , szPreviousValue , eItemType_Parameter ) ; <nl> + return ShowSelectDialog ( context , szPreviousValue , EItemType : : Parameter ) ; <nl> } <nl> <nl> dll_string AudioEnvironmentSelector ( const SResourceSelectorContext & context , const char * szPreviousValue ) <nl> { <nl> - return ShowSelectDialog ( context , szPreviousValue , eItemType_Environment ) ; <nl> + return ShowSelectDialog ( context , szPreviousValue , EItemType : : Environment ) ; <nl> } <nl> <nl> dll_string AudioPreloadRequestSelector ( const SResourceSelectorContext & context , const char * szPreviousValue ) <nl> { <nl> - return ShowSelectDialog ( context , szPreviousValue , eItemType_Preload ) ; <nl> + return ShowSelectDialog ( context , szPreviousValue , EItemType : : Preload ) ; <nl> } <nl> <nl> REGISTER_RESOURCE_SELECTOR ( " AudioTrigger " , AudioTriggerSelector , " " ) <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / SystemControlsEditorIcons . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / SystemControlsEditorIcons . h <nl> <nl> <nl> # pragma once <nl> <nl> - # include < CryIcon . h > <nl> # include " AudioAssets . h " <nl> + # include < CryIcon . h > <nl> <nl> namespace ACE <nl> { <nl> inline CryIcon GetItemTypeIcon ( EItemType const type ) <nl> { <nl> switch ( type ) <nl> { <nl> - case EItemType : : eItemType_Trigger : <nl> + case EItemType : : Trigger : <nl> return CryIcon ( " : Icons / Trigger . ico " ) ; <nl> - case EItemType : : eItemType_Parameter : <nl> + case EItemType : : Parameter : <nl> return CryIcon ( " : Icons / Parameter . ico " ) ; <nl> - case EItemType : : eItemType_Switch : <nl> + case EItemType : : Switch : <nl> return CryIcon ( " : Icons / Switch . ico " ) ; <nl> - case EItemType : : eItemType_State : <nl> - return CryIcon ( " : Icons / Property . ico " ) ; <nl> - case EItemType : : eItemType_Environment : <nl> + case EItemType : : State : <nl> + return CryIcon ( " : Icons / State . ico " ) ; <nl> + case EItemType : : Environment : <nl> return CryIcon ( " : Icons / Environment . ico " ) ; <nl> - case EItemType : : eItemType_Preload : <nl> - return CryIcon ( " : Icons / Bank . ico " ) ; <nl> - case EItemType : : eItemType_Folder : <nl> - return CryIcon ( " : Icons / Folder . ico " ) ; <nl> - case EItemType : : eItemType_Library : <nl> - return CryIcon ( " icons : common / assets_geomcache . ico " ) ; <nl> + case EItemType : : Preload : <nl> + return CryIcon ( " : Icons / Preload . ico " ) ; <nl> + case EItemType : : Folder : <nl> + return CryIcon ( " icons : General / Folder . ico " ) ; <nl> + case EItemType : : Library : <nl> + return CryIcon ( " icons : General / File . ico " ) ; <nl> } <nl> return CryIcon ( " icons : Dialogs / dialog - error . ico " ) ; <nl> } <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / SystemControlsModel . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / SystemControlsModel . cpp <nl> <nl> <nl> # include " StdAfx . h " <nl> # include " SystemControlsModel . h " <nl> - # include " SystemControlsEditorIcons . h " <nl> - <nl> - # include < QtUtil . h > <nl> <nl> # include " AudioControlsEditorPlugin . h " <nl> # include " MiddlewareDataModel . h " <nl> - # include " IAudioSystemItem . h " <nl> - # include " EditorStyleHelper . h " <nl> + # include " SystemControlsEditorIcons . h " <nl> + <nl> + # include < IAudioSystemItem . h > <nl> + # include < QtUtil . h > <nl> + # include < EditorStyleHelper . h > <nl> <nl> # include < DragDrop . h > <nl> <nl> bool IsParentValid ( CAudioAsset const & parent , EItemType const type ) <nl> { <nl> switch ( parent . GetType ( ) ) <nl> { <nl> - case EItemType : : eItemType_Folder : <nl> - case EItemType : : eItemType_Library : / / intentional fall through <nl> - return type ! = eItemType_State ; <nl> + case EItemType : : Folder : <nl> + case EItemType : : Library : / / intentional fall through <nl> + return type ! = EItemType : : State ; <nl> default : / / assumes the rest are actual controls <nl> { <nl> CAudioControl const * pControl = static_cast < CAudioControl const * > ( & parent ) ; <nl> <nl> - if ( pControl & & pControl - > GetType ( ) = = eItemType_Switch ) <nl> + if ( pControl & & ( pControl - > GetType ( ) = = EItemType : : Switch ) ) <nl> { <nl> - return type = = eItemType_State ; <nl> + return type = = EItemType : : State ; <nl> } <nl> } <nl> } <nl> void DecodeMimeData ( const QMimeData * pData , std : : vector < CAudioAsset * > & outItems ) <nl> <nl> if ( dragDropData - > HasCustomData ( " Items " ) ) <nl> { <nl> - QByteArray byteArray = dragDropData - > GetCustomData ( " Items " ) ; <nl> + QByteArray const byteArray = dragDropData - > GetCustomData ( " Items " ) ; <nl> QDataStream stream ( byteArray ) ; <nl> <nl> while ( ! stream . atEnd ( ) ) <nl> QVariant CSystemControlsModel : : data ( QModelIndex const & index , int role ) const <nl> break ; <nl> <nl> case Qt : : DecorationRole : <nl> - return GetItemTypeIcon ( EItemType : : eItemType_Library ) ; <nl> + return GetItemTypeIcon ( EItemType : : Library ) ; <nl> break ; <nl> <nl> - case EDataRole : : eDataRole_ItemType : <nl> - return EItemType : : eItemType_Library ; <nl> + case static_cast < int > ( EDataRole : : ItemType ) : <nl> + return static_cast < int > ( EItemType : : Library ) ; <nl> break ; <nl> <nl> - case EDataRole : : eDataRole_InternalPointer : <nl> + case static_cast < int > ( EDataRole : : InternalPointer ) : <nl> return reinterpret_cast < intptr_t > ( pLibrary ) ; <nl> break ; <nl> } <nl> QStringList CSystemControlsModel : : mimeTypes ( ) const <nl> void CSystemControlsModel : : ConnectToSystem ( ) <nl> { <nl> m_pAssetsManager - > signalLibraryAboutToBeAdded . Connect ( [ & ] ( ) <nl> - { <nl> - int const row = m_pAssetsManager - > GetLibraryCount ( ) ; <nl> - beginInsertRows ( QModelIndex ( ) , row , row ) ; <nl> - } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + { <nl> + int const row = m_pAssetsManager - > GetLibraryCount ( ) ; <nl> + beginInsertRows ( QModelIndex ( ) , row , row ) ; <nl> + } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> <nl> m_pAssetsManager - > signalLibraryAdded . Connect ( [ & ] ( CAudioLibrary * pLibrary ) { endInsertRows ( ) ; } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> <nl> m_pAssetsManager - > signalLibraryAboutToBeRemoved . Connect ( [ & ] ( CAudioLibrary * pLibrary ) <nl> - { <nl> - int const libCount = m_pAssetsManager - > GetLibraryCount ( ) ; <nl> + { <nl> + int const libCount = m_pAssetsManager - > GetLibraryCount ( ) ; <nl> <nl> - for ( int i = 0 ; i < libCount ; + + i ) <nl> + for ( int i = 0 ; i < libCount ; + + i ) <nl> + { <nl> + if ( m_pAssetsManager - > GetLibrary ( i ) = = pLibrary ) <nl> { <nl> - if ( m_pAssetsManager - > GetLibrary ( i ) = = pLibrary ) <nl> - { <nl> - beginRemoveRows ( QModelIndex ( ) , i , i ) ; <nl> - break ; <nl> - } <nl> + beginRemoveRows ( QModelIndex ( ) , i , i ) ; <nl> + break ; <nl> } <nl> - } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + } <nl> + } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> <nl> m_pAssetsManager - > signalLibraryRemoved . Connect ( [ & ] ( ) { endRemoveRows ( ) ; } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> } <nl> void CSystemControlsModel : : DisconnectFromSystem ( ) <nl> m_pAssetsManager - > signalLibraryRemoved . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> } <nl> <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CSystemControlsFilterProxyModel : : CSystemControlsFilterProxyModel ( QObject * parent ) <nl> - : QDeepFilterProxyModel ( QDeepFilterProxyModel : : BehaviorFlags ( QDeepFilterProxyModel : : AcceptIfChildMatches ) , parent ) <nl> - { <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - bool CSystemControlsFilterProxyModel : : rowMatchesFilter ( int source_row , QModelIndex const & source_parent ) const <nl> - { <nl> - if ( QDeepFilterProxyModel : : rowMatchesFilter ( source_row , source_parent ) ) <nl> - { <nl> - QModelIndex index = sourceModel ( ) - > index ( source_row , 0 , source_parent ) ; <nl> - <nl> - if ( index . isValid ( ) ) <nl> - { <nl> - if ( m_validControlsMask ! = std : : numeric_limits < uint > : : max ( ) ) <nl> - { <nl> - / / has filtering <nl> - EItemType const itemType = ( EItemType ) sourceModel ( ) - > data ( index , EDataRole : : eDataRole_ItemType ) . toUInt ( ) ; <nl> - <nl> - if ( itemType < eItemType_Folder ) <nl> - { <nl> - return m_validControlsMask & ( 1 < < itemType ) ; <nl> - } <nl> - else <nl> - { <nl> - return false ; <nl> - } <nl> - } <nl> - <nl> - return true ; <nl> - } <nl> - } <nl> - <nl> - return false ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - bool CSystemControlsFilterProxyModel : : lessThan ( QModelIndex const & left , QModelIndex const & right ) const <nl> - { <nl> - if ( left . column ( ) = = right . column ( ) ) <nl> - { <nl> - EItemType leftType = static_cast < EItemType > ( sourceModel ( ) - > data ( left , EDataRole : : eDataRole_ItemType ) . toInt ( ) ) ; <nl> - EItemType rightType = static_cast < EItemType > ( sourceModel ( ) - > data ( right , EDataRole : : eDataRole_ItemType ) . toInt ( ) ) ; <nl> - <nl> - if ( leftType ! = rightType ) <nl> - { <nl> - return rightType < EItemType : : eItemType_Folder ; <nl> - } <nl> - <nl> - QVariant valueLeft = sourceModel ( ) - > data ( left , Qt : : DisplayRole ) ; <nl> - QVariant valueRight = sourceModel ( ) - > data ( right , Qt : : DisplayRole ) ; <nl> - <nl> - return valueLeft < valueRight ; <nl> - } <nl> - <nl> - return QSortFilterProxyModel : : lessThan ( left , right ) ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CSystemControlsFilterProxyModel : : EnableControl ( bool const bEnabled , EItemType const type ) <nl> - { <nl> - if ( bEnabled ) <nl> - { <nl> - m_validControlsMask | = ( 1 < < ( int ) type ) ; <nl> - } <nl> - else <nl> - { <nl> - m_validControlsMask & = ~ ( 1 < < ( int ) type ) ; <nl> - } <nl> - <nl> - invalidate ( ) ; <nl> - } <nl> - <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CAudioLibraryModel : : CAudioLibraryModel ( CAudioAssetsManager * pAssetsManager , CAudioLibrary * pLibrary ) <nl> : m_pAssetsManager ( pAssetsManager ) <nl> QVariant CAudioLibraryModel : : data ( QModelIndex const & index , int role ) const <nl> switch ( role ) <nl> { <nl> case Qt : : DisplayRole : <nl> + <nl> + if ( pItem - > IsModified ( ) ) <nl> + { <nl> + return QtUtil : : ToQStringSafe ( pItem - > GetName ( ) ) + " * " ; <nl> + } <nl> + <nl> return QtUtil : : ToQStringSafe ( pItem - > GetName ( ) ) ; <nl> break ; <nl> <nl> QVariant CAudioLibraryModel : : data ( QModelIndex const & index , int role ) const <nl> { <nl> return s_noConnectionColor ; <nl> } <nl> - else if ( ( ( pItem - > GetType ( ) = = EItemType : : eItemType_Folder ) | | ( pItem - > GetType ( ) = = EItemType : : eItemType_Switch ) ) & & ! pItem - > HasControl ( ) ) <nl> + else if ( ( ( pItem - > GetType ( ) = = EItemType : : Folder ) | | ( pItem - > GetType ( ) = = EItemType : : Switch ) ) & & ! pItem - > HasControl ( ) ) <nl> { <nl> return s_noControlColor ; <nl> } <nl> QVariant CAudioLibraryModel : : data ( QModelIndex const & index , int role ) const <nl> <nl> if ( pItem - > HasPlaceholderConnection ( ) ) <nl> { <nl> - if ( ( pItem - > GetType ( ) = = EItemType : : eItemType_Folder ) | | ( pItem - > GetType ( ) = = EItemType : : eItemType_Switch ) ) <nl> + if ( ( pItem - > GetType ( ) = = EItemType : : Folder ) | | ( pItem - > GetType ( ) = = EItemType : : Switch ) ) <nl> { <nl> return tr ( " Contains item that has an invalid connection " ) ; <nl> } <nl> QVariant CAudioLibraryModel : : data ( QModelIndex const & index , int role ) const <nl> } <nl> else if ( ! pItem - > HasConnection ( ) ) <nl> { <nl> - if ( ( pItem - > GetType ( ) = = EItemType : : eItemType_Folder ) | | ( pItem - > GetType ( ) = = EItemType : : eItemType_Switch ) ) <nl> + if ( ( pItem - > GetType ( ) = = EItemType : : Folder ) | | ( pItem - > GetType ( ) = = EItemType : : Switch ) ) <nl> { <nl> return tr ( " Contains item that is not connected to any audio control " ) ; <nl> } <nl> QVariant CAudioLibraryModel : : data ( QModelIndex const & index , int role ) const <nl> return tr ( " Item is not connected to any audio control " ) ; <nl> } <nl> } <nl> - else if ( ( pItem - > GetType ( ) = = EItemType : : eItemType_Folder ) & & ! pItem - > HasControl ( ) ) <nl> + else if ( ( pItem - > GetType ( ) = = EItemType : : Folder ) & & ! pItem - > HasControl ( ) ) <nl> { <nl> return tr ( " Contains no audio control " ) ; <nl> } <nl> - else if ( ( pItem - > GetType ( ) = = EItemType : : eItemType_Switch ) & & ! pItem - > HasControl ( ) ) <nl> + else if ( ( pItem - > GetType ( ) = = EItemType : : Switch ) & & ! pItem - > HasControl ( ) ) <nl> { <nl> return tr ( " Contains no state " ) ; <nl> } <nl> QVariant CAudioLibraryModel : : data ( QModelIndex const & index , int role ) const <nl> return GetItemTypeIcon ( itemType ) ; <nl> break ; <nl> <nl> - case EDataRole : : eDataRole_ItemType : <nl> - return pItem - > GetType ( ) ; <nl> + case static_cast < int > ( EDataRole : : ItemType ) : <nl> + return static_cast < int > ( pItem - > GetType ( ) ) ; <nl> break ; <nl> <nl> - case EDataRole : : eDataRole_InternalPointer : <nl> + case static_cast < int > ( EDataRole : : InternalPointer ) : <nl> return reinterpret_cast < intptr_t > ( pItem ) ; <nl> break ; <nl> } <nl> bool CAudioLibraryModel : : setData ( QModelIndex const & index , QVariant const & value <nl> <nl> switch ( itemType ) <nl> { <nl> - case EItemType : : eItemType_Preload : <nl> - case EItemType : : eItemType_Parameter : <nl> - case EItemType : : eItemType_State : <nl> - case EItemType : : eItemType_Switch : <nl> - case EItemType : : eItemType_Trigger : <nl> - case EItemType : : eItemType_Environment : <nl> + case EItemType : : Preload : <nl> + case EItemType : : Parameter : <nl> + case EItemType : : State : <nl> + case EItemType : : Switch : <nl> + case EItemType : : Trigger : <nl> + case EItemType : : Environment : <nl> pItem - > SetName ( Utils : : GenerateUniqueControlName ( newName , itemType , * m_pAssetsManager ) ) ; <nl> pItem - > SetModified ( true ) ; <nl> break ; <nl> - case EItemType : : eItemType_Folder : <nl> + case EItemType : : Folder : <nl> pItem - > SetName ( Utils : : GenerateUniqueName ( newName , itemType , pItem - > GetParent ( ) ) ) ; <nl> pItem - > SetModified ( true ) ; <nl> break ; <nl> QModelIndex CAudioLibraryModel : : parent ( QModelIndex const & index ) const <nl> <nl> if ( pItem ) <nl> { <nl> - if ( pItem - > GetParent ( ) - > GetType ( ) ! = EItemType : : eItemType_Library ) <nl> + if ( pItem - > GetParent ( ) - > GetType ( ) ! = EItemType : : Library ) <nl> { <nl> return IndexFromItem ( pItem - > GetParent ( ) ) ; <nl> } <nl> QMimeData * CAudioLibraryModel : : mimeData ( QModelIndexList const & indexes ) const <nl> QByteArray byteArray ; <nl> QDataStream stream ( & byteArray , QIODevice : : ReadWrite ) ; <nl> <nl> - for ( auto index : indexes ) <nl> + for ( auto const index : indexes ) <nl> { <nl> stream < < reinterpret_cast < intptr_t > ( index . internalPointer ( ) ) ; <nl> } <nl> void CAudioLibraryModel : : ConnectToSystem ( ) <nl> { <nl> CAudioAssetsManager * pAssetsManager = CAudioControlsEditorPlugin : : GetAssetsManager ( ) ; <nl> pAssetsManager - > signalItemAboutToBeAdded . Connect ( [ & ] ( CAudioAsset * pParent ) <nl> + { <nl> + if ( Utils : : GetParentLibrary ( pParent ) = = m_pLibrary ) <nl> { <nl> - if ( Utils : : GetParentLibrary ( pParent ) = = m_pLibrary ) <nl> - { <nl> - int row = pParent - > ChildCount ( ) ; <nl> + int const row = pParent - > ChildCount ( ) ; <nl> <nl> - if ( pParent - > GetType ( ) = = EItemType : : eItemType_Library ) <nl> - { <nl> - CRY_ASSERT ( pParent = = m_pLibrary ) ; <nl> - beginInsertRows ( QModelIndex ( ) , row , row ) ; <nl> - } <nl> - else <nl> - { <nl> - QModelIndex parent = IndexFromItem ( pParent ) ; <nl> - beginInsertRows ( parent , row , row ) ; <nl> - } <nl> + if ( pParent - > GetType ( ) = = EItemType : : Library ) <nl> + { <nl> + CRY_ASSERT ( pParent = = m_pLibrary ) ; <nl> + beginInsertRows ( QModelIndex ( ) , row , row ) ; <nl> + } <nl> + else <nl> + { <nl> + QModelIndex parent = IndexFromItem ( pParent ) ; <nl> + beginInsertRows ( parent , row , row ) ; <nl> } <nl> - } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + } <nl> + } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> <nl> pAssetsManager - > signalItemAdded . Connect ( [ & ] ( CAudioAsset * pAsset ) <nl> + { <nl> + if ( Utils : : GetParentLibrary ( pAsset ) = = m_pLibrary ) <nl> { <nl> - if ( Utils : : GetParentLibrary ( pAsset ) = = m_pLibrary ) <nl> - { <nl> - endInsertRows ( ) ; <nl> - } <nl> - } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + endInsertRows ( ) ; <nl> + } <nl> + } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> <nl> pAssetsManager - > signalItemAboutToBeRemoved . Connect ( [ & ] ( CAudioAsset * pAsset ) <nl> + { <nl> + if ( Utils : : GetParentLibrary ( pAsset ) = = m_pLibrary ) <nl> { <nl> - if ( Utils : : GetParentLibrary ( pAsset ) = = m_pLibrary ) <nl> - { <nl> - CAudioAsset * pParent = pAsset - > GetParent ( ) ; <nl> - int const childCount = pParent - > ChildCount ( ) ; <nl> + CAudioAsset * pParent = pAsset - > GetParent ( ) ; <nl> + int const childCount = pParent - > ChildCount ( ) ; <nl> <nl> - for ( int i = 0 ; i < childCount ; + + i ) <nl> + for ( int i = 0 ; i < childCount ; + + i ) <nl> + { <nl> + if ( pParent - > GetChild ( i ) = = pAsset ) <nl> { <nl> - if ( pParent - > GetChild ( i ) = = pAsset ) <nl> + if ( pParent - > GetType ( ) = = EItemType : : Library ) <nl> { <nl> - if ( pParent - > GetType ( ) = = EItemType : : eItemType_Library ) <nl> - { <nl> - CRY_ASSERT ( pParent = = m_pLibrary ) ; <nl> - beginRemoveRows ( QModelIndex ( ) , i , i ) ; <nl> - } <nl> - else <nl> - { <nl> - QModelIndex parent = IndexFromItem ( pParent ) ; <nl> - beginRemoveRows ( parent , i , i ) ; <nl> - } <nl> - <nl> - break ; <nl> + CRY_ASSERT ( pParent = = m_pLibrary ) ; <nl> + beginRemoveRows ( QModelIndex ( ) , i , i ) ; <nl> } <nl> + else <nl> + { <nl> + QModelIndex parent = IndexFromItem ( pParent ) ; <nl> + beginRemoveRows ( parent , i , i ) ; <nl> + } <nl> + <nl> + break ; <nl> } <nl> } <nl> - } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + } <nl> + } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> <nl> pAssetsManager - > signalItemRemoved . Connect ( [ & ] ( CAudioAsset * pParent , CAudioAsset * pAsset ) <nl> + { <nl> + if ( Utils : : GetParentLibrary ( pParent ) = = m_pLibrary ) <nl> { <nl> - if ( Utils : : GetParentLibrary ( pParent ) = = m_pLibrary ) <nl> - { <nl> - endRemoveRows ( ) ; <nl> - } <nl> - } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + endRemoveRows ( ) ; <nl> + } <nl> + } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CAudioLibraryModel : : DisconnectFromSystem ( ) <nl> pAssetsManager - > signalItemRemoved . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + CSystemControlsFilterProxyModel : : CSystemControlsFilterProxyModel ( QObject * parent ) <nl> + : QDeepFilterProxyModel ( QDeepFilterProxyModel : : BehaviorFlags ( QDeepFilterProxyModel : : AcceptIfChildMatches ) , parent ) <nl> + { <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + bool CSystemControlsFilterProxyModel : : rowMatchesFilter ( int source_row , QModelIndex const & source_parent ) const <nl> + { <nl> + if ( QDeepFilterProxyModel : : rowMatchesFilter ( source_row , source_parent ) ) <nl> + { <nl> + QModelIndex const index = sourceModel ( ) - > index ( source_row , 0 , source_parent ) ; <nl> + <nl> + if ( index . isValid ( ) ) <nl> + { <nl> + if ( m_validControlsMask ! = std : : numeric_limits < uint > : : max ( ) ) <nl> + { <nl> + / / Has type filtering . <nl> + EItemType const itemType = ( EItemType ) sourceModel ( ) - > data ( index , static_cast < int > ( EDataRole : : ItemType ) ) . toUInt ( ) ; <nl> + <nl> + if ( itemType < EItemType : : Folder ) <nl> + { <nl> + return m_validControlsMask & ( 1 < < static_cast < int > ( itemType ) ) ; <nl> + } <nl> + else <nl> + { <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + } <nl> + <nl> + return false ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + bool CSystemControlsFilterProxyModel : : lessThan ( QModelIndex const & left , QModelIndex const & right ) const <nl> + { <nl> + if ( left . column ( ) = = right . column ( ) ) <nl> + { <nl> + EItemType const leftType = static_cast < EItemType > ( sourceModel ( ) - > data ( left , static_cast < int > ( EDataRole : : ItemType ) ) . toInt ( ) ) ; <nl> + EItemType const rightType = static_cast < EItemType > ( sourceModel ( ) - > data ( right , static_cast < int > ( EDataRole : : ItemType ) ) . toInt ( ) ) ; <nl> + <nl> + if ( leftType ! = rightType ) <nl> + { <nl> + return rightType < EItemType : : Folder ; <nl> + } <nl> + <nl> + QVariant const valueLeft = sourceModel ( ) - > data ( left , Qt : : DisplayRole ) ; <nl> + QVariant const valueRight = sourceModel ( ) - > data ( right , Qt : : DisplayRole ) ; <nl> + <nl> + return valueLeft < valueRight ; <nl> + } <nl> + <nl> + return QSortFilterProxyModel : : lessThan ( left , right ) ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + void CSystemControlsFilterProxyModel : : EnableControl ( bool const bEnabled , EItemType const type ) <nl> + { <nl> + if ( bEnabled ) <nl> + { <nl> + m_validControlsMask | = ( 1 < < ( int ) type ) ; <nl> + } <nl> + else <nl> + { <nl> + m_validControlsMask & = ~ ( 1 < < ( int ) type ) ; <nl> + } <nl> + <nl> + invalidate ( ) ; <nl> + } <nl> + <nl> namespace AudioModelUtils <nl> { <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void GetAssetsFromIndices ( QModelIndexList const & list , std : : vector < CAudioLibrary * > & outLibraries , std : : vector < CAudioFolder * > & outFolders , std : : vector < CAudioControl * > & outControls ) <nl> { <nl> - for ( auto & index : list ) <nl> + for ( auto const & index : list ) <nl> { <nl> - QVariant internalPtr = index . data ( EDataRole : : eDataRole_InternalPointer ) ; <nl> + QVariant const internalPtr = index . data ( static_cast < int > ( EDataRole : : InternalPointer ) ) ; <nl> <nl> if ( internalPtr . isValid ( ) ) <nl> { <nl> - QVariant type = index . data ( EDataRole : : eDataRole_ItemType ) ; <nl> + QVariant const type = index . data ( static_cast < int > ( EDataRole : : ItemType ) ) ; <nl> <nl> switch ( type . toInt ( ) ) <nl> { <nl> - case EItemType : : eItemType_Library : <nl> + case static_cast < int > ( EItemType : : Library ) : <nl> outLibraries . push_back ( reinterpret_cast < CAudioLibrary * > ( internalPtr . value < intptr_t > ( ) ) ) ; <nl> break ; <nl> - case EItemType : : eItemType_Folder : <nl> + case static_cast < int > ( EItemType : : Folder ) : <nl> outFolders . push_back ( reinterpret_cast < CAudioFolder * > ( internalPtr . value < intptr_t > ( ) ) ) ; <nl> break ; <nl> default : <nl> void GetAssetsFromIndices ( QModelIndexList const & list , std : : vector < CAudioLibrary <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CAudioAsset * GetAssetFromIndex ( QModelIndex const & index ) <nl> { <nl> - QVariant internalPtr = index . data ( EDataRole : : eDataRole_InternalPointer ) ; <nl> + QVariant const internalPtr = index . data ( static_cast < int > ( EDataRole : : InternalPointer ) ) ; <nl> <nl> if ( internalPtr . isValid ( ) ) <nl> { <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / SystemControlsModel . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / SystemControlsModel . h <nl> <nl> <nl> # pragma once <nl> <nl> - # include < QAbstractItemModel > <nl> # include < ProxyModels / DeepFilterProxyModel . h > <nl> - <nl> - enum EDataRole <nl> - { <nl> - eDataRole_ItemType = Qt : : UserRole + 1 , <nl> - eDataRole_Modified , <nl> - eDataRole_InternalPointer <nl> - } ; <nl> + # include < ACETypes . h > <nl> <nl> namespace ACE <nl> { <nl> class CAudioLibrary ; <nl> class CAudioFolder ; <nl> class CAudioAsset ; <nl> class CAudioAssetsManager ; <nl> - enum EItemType ; <nl> + <nl> + enum class EDataRole <nl> + { <nl> + ItemType = Qt : : UserRole + 1 , <nl> + Modified , <nl> + InternalPointer <nl> + } ; <nl> <nl> namespace AudioModelUtils <nl> { <nl> void GetAssetsFromIndices ( QModelIndexList const & list , std : : vector < CAudioLibrary * > & outLibraries , std : : vector < CAudioFolder * > & outFolders , std : : vector < CAudioControl * > & outControls ) ; <nl> - CAudioAsset * GetAssetFromIndex ( const QModelIndex & index ) ; <nl> + CAudioAsset * GetAssetFromIndex ( QModelIndex const & index ) ; <nl> } / / namespace AudioModelUtils <nl> <nl> class CSystemControlsModel : public QAbstractItemModel <nl> class CSystemControlsModel : public QAbstractItemModel <nl> CAudioAssetsManager * m_pAssetsManager = nullptr ; <nl> } ; <nl> <nl> - class CSystemControlsFilterProxyModel final : public QDeepFilterProxyModel <nl> - { <nl> - public : <nl> - <nl> - CSystemControlsFilterProxyModel ( QObject * parent ) ; <nl> - <nl> - / / QDeepFilterProxyModel <nl> - virtual bool rowMatchesFilter ( int source_row , QModelIndex const & source_parent ) const override ; <nl> - / / ~ QDeepFilterProxyModel <nl> - <nl> - / / QSortFilterProxyModel <nl> - virtual bool lessThan ( QModelIndex const & left , QModelIndex const & right ) const override ; <nl> - / / ~ QSortFilterProxyModel <nl> - <nl> - void EnableControl ( bool const bEnabled , EItemType const type ) ; <nl> - <nl> - private : <nl> - <nl> - uint m_validControlsMask = std : : numeric_limits < uint > : : max ( ) ; <nl> - } ; <nl> - <nl> class CAudioLibraryModel : public QAbstractItemModel <nl> { <nl> public : <nl> class CAudioLibraryModel : public QAbstractItemModel <nl> CAudioAssetsManager * m_pAssetsManager = nullptr ; <nl> CAudioLibrary * m_pLibrary = nullptr ; <nl> } ; <nl> + <nl> + class CSystemControlsFilterProxyModel final : public QDeepFilterProxyModel <nl> + { <nl> + public : <nl> + <nl> + CSystemControlsFilterProxyModel ( QObject * parent ) ; <nl> + <nl> + / / QDeepFilterProxyModel <nl> + virtual bool rowMatchesFilter ( int source_row , QModelIndex const & source_parent ) const override ; <nl> + / / ~ QDeepFilterProxyModel <nl> + <nl> + / / QSortFilterProxyModel <nl> + virtual bool lessThan ( QModelIndex const & left , QModelIndex const & right ) const override ; <nl> + / / ~ QSortFilterProxyModel <nl> + <nl> + void EnableControl ( bool const bEnabled , EItemType const type ) ; <nl> + <nl> + private : <nl> + <nl> + uint m_validControlsMask = std : : numeric_limits < uint > : : max ( ) ; <nl> + } ; <nl> } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / SystemControlsWidget . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / SystemControlsWidget . cpp <nl> <nl> # include " StdAfx . h " <nl> # include " SystemControlsWidget . h " <nl> <nl> + # include " SystemControlsModel . h " <nl> # include " AudioControlsEditorPlugin . h " <nl> # include " MiddlewareDataWidget . h " <nl> # include " MiddlewareDataModel . h " <nl> # include " AudioAssets . h " <nl> # include " AudioAssetsManager . h " <nl> # include " SystemControlsEditorIcons . h " <nl> - # include " AdvancedTreeView . h " <nl> + # include " AudioTreeView . h " <nl> <nl> - # include < IEditor . h > <nl> - # include < CrySystem / File / CryFile . h > <nl> - # include < CryString / CryPath . h > <nl> - # include < CryMath / Cry_Camera . h > <nl> - # include < CryIcon . h > <nl> # include < CryAudio / IAudioSystem . h > <nl> # include < IAudioSystemEditor . h > <nl> # include < IAudioSystemItem . h > <nl> + # include < IEditor . h > <nl> # include < QtUtil . h > <nl> # include < EditorStyleHelper . h > <nl> - # include < IUndoObject . h > <nl> - # include < Controls / QuestionDialog . h > <nl> # include < FilePathUtil . h > <nl> + # include < CrySystem / File / CryFile . h > <nl> + # include < CryString / CryPath . h > <nl> + # include < CryMath / Cry_Camera . h > <nl> + # include < CryIcon . h > <nl> + # include < Controls / QuestionDialog . h > <nl> # include < ProxyModels / MountingProxyModel . h > <nl> # include < QSearchBox . h > <nl> + # include < IUndoObject . h > <nl> <nl> - # include < QMenu > <nl> - # include < QPushButton > <nl> - # include < QToolButton > <nl> - # include < QCheckBox > <nl> - # include < QKeyEvent > <nl> # include < QAction > <nl> - # include < QSplitter > <nl> + # include < QCheckBox > <nl> # include < QHBoxLayout > <nl> # include < QHeaderView > <nl> + # include < QKeyEvent > <nl> + # include < QMenu > <nl> + # include < QPushButton > <nl> + # include < QSplitter > <nl> + # include < QToolButton > <nl> # include < QVBoxLayout > <nl> <nl> <nl> namespace ACE <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CSystemControlsWidget : : CSystemControlsWidget ( CAudioAssetsManager * pAssetsManager ) <nl> : m_pAssetsManager ( pAssetsManager ) <nl> - , m_pProxyModel ( new CSystemControlsFilterProxyModel ( this ) ) <nl> + , m_pFilterProxyModel ( new CSystemControlsFilterProxyModel ( this ) ) <nl> { <nl> + m_pAssetsModel = new CSystemControlsModel ( m_pAssetsManager ) ; <nl> + <nl> + auto const libCount = m_pAssetsManager - > GetLibraryCount ( ) ; <nl> + m_libraryModels . resize ( libCount ) ; <nl> + <nl> + for ( int i = 0 ; i < libCount ; + + i ) <nl> + { <nl> + m_libraryModels [ i ] = new CAudioLibraryModel ( m_pAssetsManager , m_pAssetsManager - > GetLibrary ( i ) ) ; <nl> + } <nl> + <nl> + m_pMountingProxyModel = new CMountingProxyModel ( WrapMemberFunction ( this , & CSystemControlsWidget : : CreateLibraryModelFromIndex ) ) ; <nl> + m_pMountingProxyModel - > SetHeaderDataCallbacks ( 1 , & GetHeaderData ) ; <nl> + m_pMountingProxyModel - > SetSourceModel ( m_pAssetsModel ) ; <nl> + <nl> + m_pFilterProxyModel - > setSourceModel ( m_pMountingProxyModel ) ; <nl> + m_pFilterProxyModel - > setDynamicSortFilter ( true ) ; <nl> + <nl> setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Preferred ) ; <nl> <nl> QVBoxLayout * pMainLayout = new QVBoxLayout ( this ) ; <nl> pMainLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ; <nl> <nl> - m_pSearchBox = new QSearchBox ( ) ; <nl> - m_pSearchBox - > setToolTip ( tr ( " Show only controls with this name " ) ) ; <nl> + QSplitter * pSplitter = new QSplitter ( ) ; <nl> + pSplitter - > setOrientation ( Qt : : Vertical ) ; <nl> + pSplitter - > setChildrenCollapsible ( false ) ; <nl> + <nl> + InitFilterWidgets ( pMainLayout ) ; <nl> + pSplitter - > addWidget ( m_pFilterWidget ) ; <nl> + <nl> + m_pTreeView = new CAudioTreeView ( ) ; <nl> + m_pTreeView - > setEditTriggers ( QAbstractItemView : : EditKeyPressed | QAbstractItemView : : SelectedClicked ) ; <nl> + m_pTreeView - > setDragEnabled ( true ) ; <nl> + m_pTreeView - > setDragDropMode ( QAbstractItemView : : DragDrop ) ; <nl> + m_pTreeView - > setDefaultDropAction ( Qt : : MoveAction ) ; <nl> + m_pTreeView - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ; <nl> + m_pTreeView - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ; <nl> + m_pTreeView - > setModel ( m_pFilterProxyModel ) ; <nl> + m_pTreeView - > sortByColumn ( 0 , Qt : : AscendingOrder ) ; <nl> + m_pTreeView - > installEventFilter ( this ) ; <nl> + pSplitter - > addWidget ( m_pTreeView ) ; <nl> + <nl> + pSplitter - > setStretchFactor ( 0 , 0 ) ; <nl> + pSplitter - > setStretchFactor ( 1 , 1 ) ; <nl> + pMainLayout - > addWidget ( pSplitter ) ; <nl> + <nl> + QObject : : connect ( m_pTreeView , & CAudioTreeView : : customContextMenuRequested , this , & CSystemControlsWidget : : OnContextMenu ) ; <nl> + QObject : : connect ( m_pTreeView - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , this , & CSystemControlsWidget : : UpdateCreateButtons ) ; <nl> + QObject : : connect ( m_pTreeView - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , this , & CSystemControlsWidget : : SelectedControlChanged ) ; <nl> + QObject : : connect ( m_pTreeView - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , m_pTreeView , & CAudioTreeView : : OnSelectionChanged ) ; <nl> + QObject : : connect ( m_pTreeView - > selectionModel ( ) , & QItemSelectionModel : : currentChanged , this , & CSystemControlsWidget : : StopControlExecution ) ; <nl> <nl> - QToolButton * pFilterButton = new QToolButton ( ) ; <nl> - pFilterButton - > setIcon ( CryIcon ( " icons : General / Filter . ico " ) ) ; <nl> - pFilterButton - > setToolTip ( tr ( " Filters " ) ) ; <nl> - pFilterButton - > setCheckable ( true ) ; <nl> - pFilterButton - > setMaximumSize ( QSize ( 20 , 20 ) ) ; <nl> + QObject : : connect ( m_pMountingProxyModel , & CMountingProxyModel : : rowsInserted , this , & CSystemControlsWidget : : SelectNewAsset ) ; <nl> <nl> - QPushButton * pAddButton = new QPushButton ( ) ; <nl> + m_pAssetsManager - > signalItemAboutToBeAdded . Connect ( [ & ] ( CAudioAsset * pItem ) <nl> + { <nl> + ResetFilters ( ) ; <nl> + } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + <nl> + m_pAssetsManager - > signalLibraryAboutToBeAdded . Connect ( [ & ] ( ) <nl> + { <nl> + ResetFilters ( ) ; <nl> + } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + <nl> + m_pAssetsManager - > signalLibraryAboutToBeRemoved . Connect ( [ & ] ( CAudioLibrary * pLibrary ) <nl> + { <nl> + int const libCount = m_pAssetsManager - > GetLibraryCount ( ) ; <nl> + <nl> + for ( int i = 0 ; i < libCount ; + + i ) <nl> + { <nl> + if ( m_pAssetsManager - > GetLibrary ( i ) = = pLibrary ) <nl> + { <nl> + m_libraryModels [ i ] - > deleteLater ( ) ; <nl> + m_libraryModels . erase ( m_libraryModels . begin ( ) + i ) ; <nl> + break ; <nl> + } <nl> + } <nl> + } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + CSystemControlsWidget : : ~ CSystemControlsWidget ( ) <nl> + { <nl> + m_pAssetsManager - > signalLibraryAboutToBeRemoved . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + m_pAssetsManager - > signalItemAboutToBeAdded . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + m_pAssetsManager - > signalLibraryAboutToBeAdded . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + <nl> + StopControlExecution ( ) ; <nl> + delete m_pAssetsModel ; <nl> + <nl> + int const libCount = m_libraryModels . size ( ) ; <nl> + <nl> + for ( int i = 0 ; i < libCount ; + + i ) <nl> + { <nl> + m_libraryModels [ i ] - > DisconnectFromSystem ( ) ; <nl> + delete m_libraryModels [ i ] ; <nl> + } <nl> + <nl> + m_libraryModels . clear ( ) ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + void CSystemControlsWidget : : InitAddControlWidget ( QHBoxLayout * pLayout ) <nl> + { <nl> + QPushButton * pAddButton = new QPushButton ( tr ( " Add " ) ) ; <nl> pAddButton - > setToolTip ( tr ( " Add new library , folder or control " ) ) ; <nl> - pAddButton - > setText ( tr ( " Add " ) ) ; <nl> <nl> - QHBoxLayout * pHorizontalLayout = new QHBoxLayout ( ) ; <nl> - pHorizontalLayout - > addWidget ( m_pSearchBox ) ; <nl> - pHorizontalLayout - > addWidget ( pFilterButton ) ; <nl> - pHorizontalLayout - > addWidget ( pAddButton ) ; <nl> + QMenu * pAddButtonMenu = new QMenu ( ) ; <nl> + <nl> + pAddButtonMenu - > addAction ( GetItemTypeIcon ( EItemType : : Library ) , tr ( " Library " ) , [ & ] ( ) <nl> + { <nl> + m_bCreatedFromMenu = true ; <nl> + m_pAssetsManager - > CreateLibrary ( Utils : : GenerateUniqueLibraryName ( " new_library " , * m_pAssetsManager ) ) ; <nl> + } ) ; <nl> + <nl> + pAddButtonMenu - > addSeparator ( ) ; <nl> + <nl> + m_pCreateFolderAction = new QAction ( GetItemTypeIcon ( EItemType : : Folder ) , tr ( " Folder " ) , pAddButtonMenu ) ; <nl> + QObject : : connect ( m_pCreateFolderAction , & QAction : : triggered , [ & ] ( ) { CreateFolder ( GetSelectedAsset ( ) ) ; } ) ; <nl> + m_pCreateFolderAction - > setVisible ( false ) ; <nl> + pAddButtonMenu - > addAction ( m_pCreateFolderAction ) ; <nl> + <nl> + m_pCreateTriggerAction = new QAction ( GetItemTypeIcon ( EItemType : : Trigger ) , tr ( " Trigger " ) , pAddButtonMenu ) ; <nl> + QObject : : connect ( m_pCreateTriggerAction , & QAction : : triggered , [ & ] ( ) { CreateControl ( " new_trigger " , EItemType : : Trigger , GetSelectedAsset ( ) ) ; } ) ; <nl> + m_pCreateTriggerAction - > setVisible ( false ) ; <nl> + pAddButtonMenu - > addAction ( m_pCreateTriggerAction ) ; <nl> + <nl> + m_pCreateParameterAction = new QAction ( GetItemTypeIcon ( EItemType : : Parameter ) , tr ( " Parameter " ) , pAddButtonMenu ) ; <nl> + QObject : : connect ( m_pCreateParameterAction , & QAction : : triggered , [ & ] ( ) { CreateControl ( " new_parameter " , EItemType : : Parameter , GetSelectedAsset ( ) ) ; } ) ; <nl> + m_pCreateParameterAction - > setVisible ( false ) ; <nl> + pAddButtonMenu - > addAction ( m_pCreateParameterAction ) ; <nl> + <nl> + m_pCreateSwitchAction = new QAction ( GetItemTypeIcon ( EItemType : : Switch ) , tr ( " Switch " ) , pAddButtonMenu ) ; <nl> + QObject : : connect ( m_pCreateSwitchAction , & QAction : : triggered , [ & ] ( ) { CreateControl ( " new_switch " , EItemType : : Switch , GetSelectedAsset ( ) ) ; } ) ; <nl> + m_pCreateSwitchAction - > setVisible ( false ) ; <nl> + pAddButtonMenu - > addAction ( m_pCreateSwitchAction ) ; <nl> + <nl> + m_pCreateStateAction = new QAction ( GetItemTypeIcon ( EItemType : : State ) , tr ( " State " ) , pAddButtonMenu ) ; <nl> + QObject : : connect ( m_pCreateStateAction , & QAction : : triggered , [ & ] ( ) { CreateControl ( " new_state " , EItemType : : State , GetSelectedAsset ( ) ) ; } ) ; <nl> + m_pCreateStateAction - > setVisible ( false ) ; <nl> + pAddButtonMenu - > addAction ( m_pCreateStateAction ) ; <nl> + <nl> + m_pCreateEnvironmentAction = new QAction ( GetItemTypeIcon ( EItemType : : Environment ) , tr ( " Environment " ) , pAddButtonMenu ) ; <nl> + QObject : : connect ( m_pCreateEnvironmentAction , & QAction : : triggered , [ & ] ( ) { CreateControl ( " new_environment " , EItemType : : Environment , GetSelectedAsset ( ) ) ; } ) ; <nl> + m_pCreateEnvironmentAction - > setVisible ( false ) ; <nl> + pAddButtonMenu - > addAction ( m_pCreateEnvironmentAction ) ; <nl> + <nl> + m_pCreatePreloadAction = new QAction ( GetItemTypeIcon ( EItemType : : Preload ) , tr ( " Preload " ) , pAddButtonMenu ) ; <nl> + QObject : : connect ( m_pCreatePreloadAction , & QAction : : triggered , [ & ] ( ) { CreateControl ( " new_preload " , EItemType : : Preload , GetSelectedAsset ( ) ) ; } ) ; <nl> + m_pCreatePreloadAction - > setVisible ( false ) ; <nl> + pAddButtonMenu - > addAction ( m_pCreatePreloadAction ) ; <nl> + <nl> + pAddButton - > setMenu ( pAddButtonMenu ) ; <nl> + pLayout - > addWidget ( pAddButton ) ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + void CSystemControlsWidget : : InitFilterWidgets ( QVBoxLayout * pMainLayout ) <nl> + { <nl> + QHBoxLayout * pFilterLayout = new QHBoxLayout ( ) ; <nl> + <nl> + m_pSearchBox = new QSearchBox ( ) ; <nl> + pFilterLayout - > addWidget ( m_pSearchBox ) ; <nl> + <nl> + m_pFilterButton = new QToolButton ( ) ; <nl> + m_pFilterButton - > setIcon ( CryIcon ( " icons : General / Filter . ico " ) ) ; <nl> + m_pFilterButton - > setToolTip ( tr ( " Show Control Type Filters " ) ) ; <nl> + m_pFilterButton - > setCheckable ( true ) ; <nl> + m_pFilterButton - > setMaximumSize ( QSize ( 20 , 20 ) ) ; <nl> + pFilterLayout - > addWidget ( m_pFilterButton ) ; <nl> + <nl> + InitAddControlWidget ( pFilterLayout ) ; <nl> <nl> m_pFilterWidget = new QWidget ( ) ; <nl> - InitFilterWidget ( ) ; <nl> - <nl> - m_pControlsTree = new CAdvancedTreeView ( ) ; <nl> - m_pControlsTree - > setEditTriggers ( QAbstractItemView : : EditKeyPressed | QAbstractItemView : : SelectedClicked ) ; <nl> - m_pControlsTree - > setDragEnabled ( true ) ; <nl> - m_pControlsTree - > setDragDropMode ( QAbstractItemView : : DragDrop ) ; <nl> - m_pControlsTree - > setDefaultDropAction ( Qt : : MoveAction ) ; <nl> - m_pControlsTree - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ; <nl> - m_pControlsTree - > setSortingEnabled ( true ) ; <nl> - m_pControlsTree - > sortByColumn ( 0 , Qt : : AscendingOrder ) ; <nl> - m_pControlsTree - > header ( ) - > setVisible ( false ) ; <nl> - m_pControlsTree - > installEventFilter ( this ) ; <nl> - m_pControlsTree - > viewport ( ) - > installEventFilter ( this ) ; <nl> + InitTypeFilters ( ) ; <nl> <nl> - QSplitter * pSplitter = new QSplitter ( ) ; <nl> - pSplitter - > setOrientation ( Qt : : Vertical ) ; <nl> - pSplitter - > setChildrenCollapsible ( false ) ; <nl> - pSplitter - > addWidget ( m_pFilterWidget ) ; <nl> - pSplitter - > addWidget ( m_pControlsTree ) ; <nl> - pSplitter - > setStretchFactor ( 0 , 0 ) ; <nl> - pSplitter - > setStretchFactor ( 1 , 1 ) ; <nl> + QObject : : connect ( m_pFilterButton , & QToolButton : : toggled , [ & ] ( bool const bChecked ) <nl> + { <nl> + m_pFilterWidget - > setVisible ( bChecked ) ; <nl> + <nl> + if ( bChecked ) <nl> + { <nl> + m_pFilterButton - > setToolTip ( tr ( " Hide Control Type Filters " ) ) ; <nl> + } <nl> + else <nl> + { <nl> + m_pFilterButton - > setToolTip ( tr ( " Show Control Type Filters " ) ) ; <nl> + } <nl> + } ) ; <nl> <nl> - pMainLayout - > addLayout ( pHorizontalLayout ) ; <nl> - pMainLayout - > addWidget ( pSplitter ) ; <nl> <nl> - QObject : : connect ( pFilterButton , & QToolButton : : toggled , m_pFilterWidget , & QWidget : : setVisible ) ; <nl> QObject : : connect ( m_pSearchBox , & QSearchBox : : textChanged , [ & ] ( QString const & filter ) <nl> { <nl> if ( m_filter ! = filter ) <nl> CSystemControlsWidget : : CSystemControlsWidget ( CAudioAssetsManager * pAssetsManager <nl> { <nl> BackupTreeViewStates ( ) ; <nl> StartTextFiltering ( ) ; <nl> - m_pControlsTree - > expandAll ( ) ; <nl> + m_pTreeView - > expandAll ( ) ; <nl> } <nl> else if ( ! m_filter . isEmpty ( ) & & filter . isEmpty ( ) ) <nl> { <nl> - m_pProxyModel - > setFilterFixedString ( filter ) ; <nl> - m_pControlsTree - > collapseAll ( ) ; <nl> + m_pFilterProxyModel - > setFilterFixedString ( filter ) ; <nl> + m_pTreeView - > collapseAll ( ) ; <nl> RestoreTreeViewStates ( ) ; <nl> StopTextFiltering ( ) ; <nl> } <nl> else if ( ! m_filter . isEmpty ( ) & & ! filter . isEmpty ( ) ) <nl> { <nl> - m_pProxyModel - > setFilterFixedString ( filter ) ; <nl> - m_pControlsTree - > expandAll ( ) ; <nl> + m_pFilterProxyModel - > setFilterFixedString ( filter ) ; <nl> + m_pTreeView - > expandAll ( ) ; <nl> } <nl> <nl> m_filter = filter ; <nl> } <nl> <nl> - m_pProxyModel - > setFilterFixedString ( filter ) ; <nl> - } ) ; <nl> - <nl> - / / * * * * * * * * * * * * Context Menu * * * * * * * * * * * * <nl> - QMenu * pContextMenu = new QMenu ( this ) ; <nl> - pContextMenu - > addAction ( GetItemTypeIcon ( eItemType_Library ) , tr ( " Library " ) , [ this ] ( ) <nl> - { <nl> - m_bCreatedFromMenu = true ; <nl> - m_pAssetsManager - > CreateLibrary ( Utils : : GenerateUniqueLibraryName ( " new_library " , * m_pAssetsManager ) ) ; <nl> + m_pFilterProxyModel - > setFilterFixedString ( filter ) ; <nl> } ) ; <nl> <nl> - pContextMenu - > addAction ( GetItemTypeIcon ( eItemType_Folder ) , tr ( " Folder " ) , [ & ] ( ) { CreateFolder ( GetSelectedAsset ( ) ) ; } ) ; <nl> - pContextMenu - > addAction ( GetItemTypeIcon ( eItemType_Trigger ) , tr ( " Trigger " ) , [ & ] ( ) { CreateControl ( " new_trigger " , eItemType_Trigger , GetSelectedAsset ( ) ) ; } ) ; <nl> - pContextMenu - > addAction ( GetItemTypeIcon ( eItemType_Parameter ) , tr ( " Parameter " ) , [ & ] ( ) { CreateControl ( " new_parameter " , eItemType_Parameter , GetSelectedAsset ( ) ) ; } ) ; <nl> - pContextMenu - > addAction ( GetItemTypeIcon ( eItemType_Switch ) , tr ( " Switch " ) , [ & ] ( ) { CreateControl ( " new_switch " , eItemType_Switch , GetSelectedAsset ( ) ) ; } ) ; <nl> - pContextMenu - > addAction ( GetItemTypeIcon ( eItemType_Environment ) , tr ( " Environment " ) , [ & ] ( ) { CreateControl ( " new_environment " , eItemType_Environment , GetSelectedAsset ( ) ) ; } ) ; <nl> - pContextMenu - > addAction ( GetItemTypeIcon ( eItemType_Preload ) , tr ( " Preload " ) , [ & ] ( ) { CreateControl ( " new_preload " , eItemType_Preload , GetSelectedAsset ( ) ) ; } ) ; <nl> - pContextMenu - > addSeparator ( ) ; <nl> - pAddButton - > setMenu ( pContextMenu ) ; <nl> - <nl> - m_pControlsTree - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ; <nl> - QObject : : connect ( m_pControlsTree , & CAdvancedTreeView : : customContextMenuRequested , this , & CSystemControlsWidget : : OnContextMenu ) ; <nl> - / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + pMainLayout - > addLayout ( pFilterLayout ) ; <nl> + } <nl> <nl> - m_pAssetsManager - > signalItemAboutToBeAdded . Connect ( [ & ] ( CAudioAsset * pItem ) <nl> - { <nl> - if ( ! m_bReloading ) <nl> - { <nl> - ResetFilters ( ) ; <nl> - } <nl> - } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + void CSystemControlsWidget : : InitTypeFilters ( ) <nl> + { <nl> + QVBoxLayout * pTypeFiltersLayout = new QVBoxLayout ( ) ; <nl> + pTypeFiltersLayout - > setContentsMargins ( 0 , 5 , 0 , 5 ) ; <nl> <nl> - m_pAssetsManager - > signalLibraryAboutToBeAdded . Connect ( [ & ] ( ) <nl> + QCheckBox * pFilterTriggersCheckbox = new QCheckBox ( tr ( " Triggers " ) ) ; <nl> + QObject : : connect ( pFilterTriggersCheckbox , & QCheckBox : : toggled , [ & ] ( bool const bShow ) <nl> { <nl> - if ( ! m_bReloading ) <nl> - { <nl> - ResetFilters ( ) ; <nl> - } <nl> - } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> - <nl> - m_pAssetsModel = new CSystemControlsModel ( m_pAssetsManager ) ; <nl> + ShowControlType ( EItemType : : Trigger , bShow ) ; <nl> + } ) ; <nl> <nl> - auto const count = m_pAssetsManager - > GetLibraryCount ( ) ; <nl> - m_libraryModels . resize ( count ) ; <nl> + pFilterTriggersCheckbox - > setChecked ( true ) ; <nl> + pFilterTriggersCheckbox - > setToolTip ( tr ( " Show / hide Triggers " ) ) ; <nl> + pFilterTriggersCheckbox - > setIcon ( GetItemTypeIcon ( EItemType : : Trigger ) ) ; <nl> + pTypeFiltersLayout - > addWidget ( pFilterTriggersCheckbox ) ; <nl> <nl> - for ( int i = 0 ; i < count ; + + i ) <nl> + QCheckBox * pFilterParametersCheckbox = new QCheckBox ( tr ( " Parameters " ) ) ; <nl> + QObject : : connect ( pFilterParametersCheckbox , & QCheckBox : : toggled , [ & ] ( bool const bShow ) <nl> { <nl> - m_libraryModels [ i ] = new CAudioLibraryModel ( m_pAssetsManager , m_pAssetsManager - > GetLibrary ( i ) ) ; <nl> - } <nl> - <nl> - m_pMountedModel = new CMountingProxyModel ( WrapMemberFunction ( this , & CSystemControlsWidget : : CreateLibraryModelFromIndex ) ) ; <nl> - m_pMountedModel - > SetHeaderDataCallbacks ( 1 , & GetHeaderData ) ; <nl> - m_pMountedModel - > SetSourceModel ( m_pAssetsModel ) ; <nl> - <nl> - m_pProxyModel - > setSourceModel ( m_pMountedModel ) ; <nl> - m_pProxyModel - > setDynamicSortFilter ( true ) ; <nl> - m_pControlsTree - > setModel ( m_pProxyModel ) ; <nl> - <nl> - QObject : : connect ( m_pControlsTree - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , this , & CSystemControlsWidget : : SelectedControlChanged ) ; <nl> - QObject : : connect ( m_pControlsTree - > selectionModel ( ) , & QItemSelectionModel : : selectionChanged , m_pControlsTree , & CAdvancedTreeView : : OnSelectionChanged ) ; <nl> - QObject : : connect ( m_pControlsTree - > selectionModel ( ) , & QItemSelectionModel : : currentChanged , this , & CSystemControlsWidget : : StopControlExecution ) ; <nl> + ShowControlType ( EItemType : : Parameter , bShow ) ; <nl> + } ) ; <nl> <nl> - QObject : : connect ( m_pMountedModel , & CMountingProxyModel : : rowsInserted , this , & CSystemControlsWidget : : SelectNewAsset ) ; <nl> + pFilterParametersCheckbox - > setChecked ( true ) ; <nl> + pFilterParametersCheckbox - > setToolTip ( tr ( " Show / hide Parameters " ) ) ; <nl> + pFilterParametersCheckbox - > setIcon ( GetItemTypeIcon ( EItemType : : Parameter ) ) ; <nl> + pTypeFiltersLayout - > addWidget ( pFilterParametersCheckbox ) ; <nl> <nl> - m_pAssetsManager - > signalLibraryAboutToBeRemoved . Connect ( [ & ] ( CAudioLibrary * pLibrary ) <nl> + QCheckBox * pFilterSwitchesCheckbox = new QCheckBox ( tr ( " Switches " ) ) ; <nl> + QObject : : connect ( pFilterSwitchesCheckbox , & QCheckBox : : toggled , [ & ] ( bool const bShow ) <nl> { <nl> - if ( ! m_bReloading ) <nl> - { <nl> - int const libCount = m_pAssetsManager - > GetLibraryCount ( ) ; <nl> + ShowControlType ( EItemType : : Switch , bShow ) ; <nl> + } ) ; <nl> <nl> - for ( int i = 0 ; i < libCount ; + + i ) <nl> - { <nl> - if ( m_pAssetsManager - > GetLibrary ( i ) = = pLibrary ) <nl> - { <nl> - m_libraryModels [ i ] - > deleteLater ( ) ; <nl> - m_libraryModels . erase ( m_libraryModels . begin ( ) + i ) ; <nl> - break ; <nl> - } <nl> - } <nl> - } <nl> - } , reinterpret_cast < uintptr_t > ( this ) ) ; <nl> - } <nl> + pFilterSwitchesCheckbox - > setChecked ( true ) ; <nl> + pFilterSwitchesCheckbox - > setToolTip ( tr ( " Show / hide Switches " ) ) ; <nl> + pFilterSwitchesCheckbox - > setIcon ( GetItemTypeIcon ( EItemType : : Switch ) ) ; <nl> + pTypeFiltersLayout - > addWidget ( pFilterSwitchesCheckbox ) ; <nl> <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - CSystemControlsWidget : : ~ CSystemControlsWidget ( ) <nl> - { <nl> - m_pAssetsManager - > signalLibraryAboutToBeRemoved . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> - m_pAssetsManager - > signalItemAboutToBeAdded . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> - m_pAssetsManager - > signalLibraryAboutToBeAdded . DisconnectById ( reinterpret_cast < uintptr_t > ( this ) ) ; <nl> + QCheckBox * pFilterEnvironmentsCheckbox = new QCheckBox ( tr ( " Environments " ) ) ; <nl> + QObject : : connect ( pFilterEnvironmentsCheckbox , & QCheckBox : : toggled , [ & ] ( bool const bShow ) <nl> + { <nl> + ShowControlType ( EItemType : : Environment , bShow ) ; <nl> + } ) ; <nl> <nl> - StopControlExecution ( ) ; <nl> - delete m_pAssetsModel ; <nl> - int const libCount = m_libraryModels . size ( ) ; <nl> + pFilterEnvironmentsCheckbox - > setChecked ( true ) ; <nl> + pFilterEnvironmentsCheckbox - > setToolTip ( tr ( " Show / hide Environments " ) ) ; <nl> + pFilterEnvironmentsCheckbox - > setIcon ( GetItemTypeIcon ( EItemType : : Environment ) ) ; <nl> + pTypeFiltersLayout - > addWidget ( pFilterEnvironmentsCheckbox ) ; <nl> <nl> - for ( int i = 0 ; i < libCount ; + + i ) <nl> + QCheckBox * pFilterPreloadsCheckbox = new QCheckBox ( tr ( " Preloads " ) ) ; <nl> + QObject : : connect ( pFilterPreloadsCheckbox , & QCheckBox : : toggled , [ & ] ( bool const bShow ) <nl> { <nl> - m_libraryModels [ i ] - > DisconnectFromSystem ( ) ; <nl> - delete m_libraryModels [ i ] ; <nl> - } <nl> + ShowControlType ( EItemType : : Preload , bShow ) ; <nl> + } ) ; <nl> <nl> - m_libraryModels . clear ( ) ; <nl> + pFilterPreloadsCheckbox - > setChecked ( true ) ; <nl> + pFilterPreloadsCheckbox - > setToolTip ( tr ( " Show / hide Preloads " ) ) ; <nl> + pFilterPreloadsCheckbox - > setIcon ( GetItemTypeIcon ( EItemType : : Preload ) ) ; <nl> + pTypeFiltersLayout - > addWidget ( pFilterPreloadsCheckbox ) ; <nl> + <nl> + m_pFilterWidget = QtUtil : : MakeScrollable ( pTypeFiltersLayout ) ; <nl> + m_pFilterWidget - > setHidden ( true ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> bool CSystemControlsWidget : : eventFilter ( QObject * pObject , QEvent * pEvent ) <nl> { <nl> - if ( ( pEvent - > type ( ) = = QEvent : : KeyRelease ) & & ! m_pControlsTree - > IsEditing ( ) ) <nl> + if ( ( pEvent - > type ( ) = = QEvent : : KeyRelease ) & & ! m_pTreeView - > IsEditing ( ) ) <nl> { <nl> QKeyEvent * pKeyEvent = static_cast < QKeyEvent * > ( pEvent ) ; <nl> <nl> bool CSystemControlsWidget : : eventFilter ( QObject * pObject , QEvent * pEvent ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> std : : vector < CAudioControl * > CSystemControlsWidget : : GetSelectedControls ( ) <nl> { <nl> - QModelIndexList indexes = m_pControlsTree - > selectionModel ( ) - > selectedIndexes ( ) ; <nl> + QModelIndexList const indexes = m_pTreeView - > selectionModel ( ) - > selectedIndexes ( ) ; <nl> std : : vector < CAudioLibrary * > libraries ; <nl> std : : vector < CAudioFolder * > folders ; <nl> std : : vector < CAudioControl * > controls ; <nl> void CSystemControlsWidget : : Reload ( ) <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CSystemControlsWidget : : ShowControlType ( EItemType type , bool bShow ) <nl> + void CSystemControlsWidget : : ShowControlType ( EItemType const type , bool const bShow ) <nl> { <nl> - m_pProxyModel - > EnableControl ( bShow , type ) ; <nl> + m_pFilterProxyModel - > EnableControl ( bShow , type ) ; <nl> <nl> - if ( type = = eItemType_Switch ) <nl> + if ( type = = EItemType : : Switch ) <nl> { <nl> - m_pProxyModel - > EnableControl ( bShow , eItemType_State ) ; <nl> + m_pFilterProxyModel - > EnableControl ( bShow , EItemType : : State ) ; <nl> } <nl> <nl> ControlTypeFiltered ( type , bShow ) ; <nl> CAudioControl * CSystemControlsWidget : : CreateControl ( string const & name , EItemTyp <nl> { <nl> m_bCreatedFromMenu = true ; <nl> <nl> - if ( type ! = eItemType_State ) <nl> + if ( type ! = EItemType : : State ) <nl> { <nl> return m_pAssetsManager - > CreateControl ( Utils : : GenerateUniqueControlName ( name , type , * m_pAssetsManager ) , type , pParent ) ; <nl> } <nl> CAudioControl * CSystemControlsWidget : : CreateControl ( string const & name , EItemTyp <nl> CAudioAsset * CSystemControlsWidget : : CreateFolder ( CAudioAsset * pParent ) <nl> { <nl> m_bCreatedFromMenu = true ; <nl> - return m_pAssetsManager - > CreateFolder ( Utils : : GenerateUniqueName ( " new_folder " , EItemType : : eItemType_Folder , pParent ) , pParent ) ; <nl> + return m_pAssetsManager - > CreateFolder ( Utils : : GenerateUniqueName ( " new_folder " , EItemType : : Folder , pParent ) , pParent ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CSystemControlsWidget : : OnContextMenu ( QPoint const & pos ) <nl> { <nl> QMenu * pContextMenu = new QMenu ( ) ; <nl> + <nl> std : : vector < CAudioLibrary * > libraries ; <nl> std : : vector < CAudioFolder * > folders ; <nl> std : : vector < CAudioControl * > controls ; <nl> - auto const selection = m_pControlsTree - > selectionModel ( ) - > selectedRows ( ) ; <nl> + <nl> + auto const selection = m_pTreeView - > selectionModel ( ) - > selectedRows ( ) ; <nl> AudioModelUtils : : GetAssetsFromIndices ( selection , libraries , folders , controls ) ; <nl> <nl> - if ( libraries . size ( ) = = 1 | | folders . size ( ) = = 1 ) <nl> + if ( ! selection . isEmpty ( ) ) <nl> { <nl> - CAudioAsset * pParent = nullptr ; <nl> - <nl> - if ( libraries . empty ( ) ) <nl> + if ( ( controls . size ( ) = = 0 ) & & ( ( libraries . size ( ) = = 1 ) | | ( folders . size ( ) = = 1 ) ) ) <nl> { <nl> - pParent = static_cast < CAudioAsset * > ( folders [ 0 ] ) ; <nl> - } <nl> - else <nl> - { <nl> - pParent = static_cast < CAudioAsset * > ( libraries [ 0 ] ) ; <nl> - } <nl> + CAudioAsset * pParent = nullptr ; <nl> <nl> - QMenu * pAddMenu = new QMenu ( tr ( " Add " ) ) ; <nl> - pAddMenu - > addAction ( GetItemTypeIcon ( eItemType_Folder ) , tr ( " Folder " ) , [ & ] ( ) { CreateFolder ( pParent ) ; } ) ; <nl> - pAddMenu - > addSeparator ( ) ; <nl> - pAddMenu - > addAction ( GetItemTypeIcon ( eItemType_Trigger ) , tr ( " Trigger " ) , [ & ] ( ) { CreateControl ( " new_trigger " , eItemType_Trigger , pParent ) ; } ) ; <nl> - pAddMenu - > addAction ( GetItemTypeIcon ( eItemType_Parameter ) , tr ( " Parameter " ) , [ & ] ( ) { CreateControl ( " new_parameter " , eItemType_Parameter , pParent ) ; } ) ; <nl> - pAddMenu - > addAction ( GetItemTypeIcon ( eItemType_Switch ) , tr ( " Switch " ) , [ & ] ( ) { CreateControl ( " new_switch " , eItemType_Switch , pParent ) ; } ) ; <nl> - pAddMenu - > addAction ( GetItemTypeIcon ( eItemType_Environment ) , tr ( " Environment " ) , [ & ] ( ) { CreateControl ( " new_environment " , eItemType_Environment , pParent ) ; } ) ; <nl> - pAddMenu - > addAction ( GetItemTypeIcon ( eItemType_Preload ) , tr ( " Preload " ) , [ & ] ( ) { CreateControl ( " new_preload " , eItemType_Preload , pParent ) ; } ) ; <nl> - pContextMenu - > addMenu ( pAddMenu ) ; <nl> - pContextMenu - > addSeparator ( ) ; <nl> + if ( libraries . empty ( ) ) <nl> + { <nl> + pParent = static_cast < CAudioAsset * > ( folders [ 0 ] ) ; <nl> + } <nl> + else <nl> + { <nl> + pParent = static_cast < CAudioAsset * > ( libraries [ 0 ] ) ; <nl> + } <nl> <nl> - if ( pParent - > GetType ( ) = = EItemType : : eItemType_Library ) <nl> - { <nl> - / / TODO : Take into account files in the " levels " folder <nl> - pContextMenu - > addAction ( tr ( " Open Containing Folder " ) , [ & ] ( ) <nl> + QMenu * pAddMenu = new QMenu ( tr ( " Add " ) ) ; <nl> + pAddMenu - > addAction ( GetItemTypeIcon ( EItemType : : Folder ) , tr ( " Folder " ) , [ & ] ( ) { CreateFolder ( pParent ) ; } ) ; <nl> + / / To do : Add parent folder and move selection into . <nl> + pAddMenu - > addSeparator ( ) ; <nl> + pAddMenu - > addAction ( GetItemTypeIcon ( EItemType : : Trigger ) , tr ( " Trigger " ) , [ & ] ( ) { CreateControl ( " new_trigger " , EItemType : : Trigger , pParent ) ; } ) ; <nl> + pAddMenu - > addAction ( GetItemTypeIcon ( EItemType : : Parameter ) , tr ( " Parameter " ) , [ & ] ( ) { CreateControl ( " new_parameter " , EItemType : : Parameter , pParent ) ; } ) ; <nl> + pAddMenu - > addAction ( GetItemTypeIcon ( EItemType : : Switch ) , tr ( " Switch " ) , [ & ] ( ) { CreateControl ( " new_switch " , EItemType : : Switch , pParent ) ; } ) ; <nl> + pAddMenu - > addAction ( GetItemTypeIcon ( EItemType : : Environment ) , tr ( " Environment " ) , [ & ] ( ) { CreateControl ( " new_environment " , EItemType : : Environment , pParent ) ; } ) ; <nl> + pAddMenu - > addAction ( GetItemTypeIcon ( EItemType : : Preload ) , tr ( " Preload " ) , [ & ] ( ) { CreateControl ( " new_preload " , EItemType : : Preload , pParent ) ; } ) ; <nl> + pContextMenu - > addMenu ( pAddMenu ) ; <nl> + pContextMenu - > addSeparator ( ) ; <nl> + <nl> + if ( pParent - > GetType ( ) = = EItemType : : Library ) <nl> + { <nl> + / / TODO : Take into account files in the " levels " folder <nl> + pContextMenu - > addAction ( tr ( " Open Containing Folder " ) , [ & ] ( ) <nl> { <nl> QtUtil : : OpenInExplorer ( PathUtil : : Make ( PathUtil : : GetGameProjectAssetsPath ( ) , Utils : : GetAssetFolder ( ) + pParent - > GetName ( ) + " . xml " ) . c_str ( ) ) ; <nl> } ) ; <nl> - } <nl> - } <nl> <nl> - if ( controls . size ( ) = = 1 ) <nl> - { <nl> - CAudioControl * pControl = controls [ 0 ] ; <nl> - <nl> - switch ( pControl - > GetType ( ) ) <nl> - { <nl> - case EItemType : : eItemType_Trigger : <nl> - pContextMenu - > addAction ( tr ( " Execute Trigger " ) , [ & ] ( ) { ExecuteControl ( ) ; } ) ; <nl> - pContextMenu - > addSeparator ( ) ; <nl> - break ; <nl> - case EItemType : : eItemType_Switch : <nl> - pContextMenu - > addAction ( GetItemTypeIcon ( eItemType_State ) , tr ( " Add State " ) , [ & ] ( ) { CreateControl ( " new_state " , eItemType_State , pControl ) ; } ) ; <nl> - pContextMenu - > addSeparator ( ) ; <nl> - break ; <nl> - case EItemType : : eItemType_Preload : <nl> - if ( pControl - > GetScope ( ) = = CCrc32 : : Compute ( " global " ) & & ! pControl - > IsAutoLoad ( ) ) <nl> - { <nl> - pContextMenu - > addAction ( tr ( " Load Global Preload Request " ) , [ & ] ( ) { gEnv - > pAudioSystem - > PreloadSingleRequest ( CryAudio : : StringToId ( pControl - > GetName ( ) ) , false ) ; } ) ; <nl> - pContextMenu - > addAction ( tr ( " Unload Global Preload Request " ) , [ & ] ( ) { gEnv - > pAudioSystem - > UnloadSingleRequest ( CryAudio : : StringToId ( pControl - > GetName ( ) ) ) ; } ) ; <nl> pContextMenu - > addSeparator ( ) ; <nl> } <nl> - break ; <nl> } <nl> - } <nl> - else <nl> - { <nl> - bool bOnlyGlobalPreloads = false ; <nl> <nl> - for ( auto const pControl : controls ) <nl> + if ( controls . size ( ) = = 1 ) <nl> { <nl> - if ( pControl - > GetType ( ) = = EItemType : : eItemType_Preload & & pControl - > GetScope ( ) = = CCrc32 : : Compute ( " global " ) & & ! pControl - > IsAutoLoad ( ) ) <nl> - { <nl> - bOnlyGlobalPreloads = true ; <nl> - } <nl> - else <nl> + CAudioControl * pControl = controls [ 0 ] ; <nl> + <nl> + switch ( pControl - > GetType ( ) ) <nl> { <nl> - bOnlyGlobalPreloads = false ; <nl> + case EItemType : : Trigger : <nl> + pContextMenu - > addAction ( tr ( " Execute Trigger " ) , [ & ] ( ) { ExecuteControl ( ) ; } ) ; <nl> + pContextMenu - > addSeparator ( ) ; <nl> + break ; <nl> + case EItemType : : Switch : <nl> + pContextMenu - > addAction ( GetItemTypeIcon ( EItemType : : State ) , tr ( " Add State " ) , [ & ] ( ) { CreateControl ( " new_state " , EItemType : : State , pControl ) ; } ) ; <nl> + pContextMenu - > addSeparator ( ) ; <nl> + break ; <nl> + case EItemType : : Preload : <nl> + if ( pControl - > GetScope ( ) = = CCrc32 : : Compute ( " global " ) & & ! pControl - > IsAutoLoad ( ) ) <nl> + { <nl> + pContextMenu - > addAction ( tr ( " Load Global Preload Request " ) , [ & ] ( ) { gEnv - > pAudioSystem - > PreloadSingleRequest ( CryAudio : : StringToId ( pControl - > GetName ( ) ) , false ) ; } ) ; <nl> + pContextMenu - > addAction ( tr ( " Unload Global Preload Request " ) , [ & ] ( ) { gEnv - > pAudioSystem - > UnloadSingleRequest ( CryAudio : : StringToId ( pControl - > GetName ( ) ) ) ; } ) ; <nl> + pContextMenu - > addSeparator ( ) ; <nl> + } <nl> break ; <nl> } <nl> } <nl> - <nl> - if ( bOnlyGlobalPreloads ) <nl> + else <nl> { <nl> - pContextMenu - > addAction ( tr ( " Load Global Preload Requests " ) , [ & ] ( ) <nl> + bool bOnlyGlobalPreloads = false ; <nl> + <nl> + for ( auto const pControl : controls ) <nl> { <nl> - for ( auto const pControl : controls ) <nl> + if ( pControl - > GetType ( ) = = EItemType : : Preload & & pControl - > GetScope ( ) = = CCrc32 : : Compute ( " global " ) & & ! pControl - > IsAutoLoad ( ) ) <nl> { <nl> - gEnv - > pAudioSystem - > PreloadSingleRequest ( CryAudio : : StringToId ( pControl - > GetName ( ) ) , false ) ; <nl> + bOnlyGlobalPreloads = true ; <nl> } <nl> - } ) ; <nl> + else <nl> + { <nl> + bOnlyGlobalPreloads = false ; <nl> + break ; <nl> + } <nl> + } <nl> <nl> - pContextMenu - > addAction ( tr ( " Unload Global Preload Requests " ) , [ & ] ( ) <nl> + if ( bOnlyGlobalPreloads ) <nl> { <nl> - for ( auto const pControl : controls ) <nl> + pContextMenu - > addAction ( tr ( " Load Global Preload Requests " ) , [ & ] ( ) <nl> { <nl> - gEnv - > pAudioSystem - > UnloadSingleRequest ( CryAudio : : StringToId ( pControl - > GetName ( ) ) ) ; <nl> - } <nl> - } ) ; <nl> + for ( auto const pControl : controls ) <nl> + { <nl> + gEnv - > pAudioSystem - > PreloadSingleRequest ( CryAudio : : StringToId ( pControl - > GetName ( ) ) , false ) ; <nl> + } <nl> + } ) ; <nl> <nl> - pContextMenu - > addSeparator ( ) ; <nl> - } <nl> - } <nl> + pContextMenu - > addAction ( tr ( " Unload Global Preload Requests " ) , [ & ] ( ) <nl> + { <nl> + for ( auto const pControl : controls ) <nl> + { <nl> + gEnv - > pAudioSystem - > UnloadSingleRequest ( CryAudio : : StringToId ( pControl - > GetName ( ) ) ) ; <nl> + } <nl> + } ) ; <nl> <nl> - pContextMenu - > addAction ( tr ( " Rename " ) , [ & ] ( ) { m_pControlsTree - > edit ( m_pControlsTree - > currentIndex ( ) ) ; } ) ; <nl> - pContextMenu - > addAction ( tr ( " Delete " ) , [ & ] ( ) { DeleteSelectedControl ( ) ; } ) ; <nl> - pContextMenu - > addSeparator ( ) ; <nl> + pContextMenu - > addSeparator ( ) ; <nl> + } <nl> + } <nl> <nl> - if ( ! selection . isEmpty ( ) ) <nl> + pContextMenu - > addAction ( tr ( " Rename " ) , [ & ] ( ) { m_pTreeView - > edit ( m_pTreeView - > currentIndex ( ) ) ; } ) ; <nl> + pContextMenu - > addAction ( tr ( " Delete " ) , [ & ] ( ) { DeleteSelectedControl ( ) ; } ) ; <nl> + pContextMenu - > addSeparator ( ) ; <nl> + pContextMenu - > addAction ( tr ( " Expand Selection " ) , [ & ] ( ) { m_pTreeView - > ExpandSelection ( m_pTreeView - > GetSelectedIndexes ( ) ) ; } ) ; <nl> + pContextMenu - > addAction ( tr ( " Collapse Selection " ) , [ & ] ( ) { m_pTreeView - > CollapseSelection ( m_pTreeView - > GetSelectedIndexes ( ) ) ; } ) ; <nl> + pContextMenu - > addSeparator ( ) ; <nl> + } <nl> + else <nl> { <nl> - pContextMenu - > addAction ( tr ( " Expand Selection " ) , [ & ] ( ) { m_pControlsTree - > ExpandSelection ( m_pControlsTree - > GetSelectedIndexes ( ) ) ; } ) ; <nl> - pContextMenu - > addAction ( tr ( " Collapse Selection " ) , [ & ] ( ) { m_pControlsTree - > CollapseSelection ( m_pControlsTree - > GetSelectedIndexes ( ) ) ; } ) ; <nl> + pContextMenu - > addAction ( GetItemTypeIcon ( EItemType : : Library ) , tr ( " Add Library " ) , [ & ] ( ) <nl> + { <nl> + m_bCreatedFromMenu = true ; <nl> + m_pAssetsManager - > CreateLibrary ( Utils : : GenerateUniqueLibraryName ( " new_library " , * m_pAssetsManager ) ) ; <nl> + } ) ; <nl> + <nl> pContextMenu - > addSeparator ( ) ; <nl> } <nl> <nl> - pContextMenu - > addAction ( tr ( " Expand All " ) , [ & ] ( ) { m_pControlsTree - > expandAll ( ) ; } ) ; <nl> - pContextMenu - > addAction ( tr ( " Collapse All " ) , [ & ] ( ) { m_pControlsTree - > collapseAll ( ) ; } ) ; <nl> + pContextMenu - > addAction ( tr ( " Expand All " ) , [ & ] ( ) { m_pTreeView - > expandAll ( ) ; } ) ; <nl> + pContextMenu - > addAction ( tr ( " Collapse All " ) , [ & ] ( ) { m_pTreeView - > collapseAll ( ) ; } ) ; <nl> <nl> - pContextMenu - > exec ( m_pControlsTree - > mapToGlobal ( pos ) ) ; <nl> + pContextMenu - > exec ( QCursor : : pos ( ) ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CSystemControlsWidget : : DeleteSelectedControl ( ) <nl> { <nl> - auto const selection = m_pControlsTree - > selectionModel ( ) - > selectedRows ( ) ; <nl> + auto const selection = m_pTreeView - > selectionModel ( ) - > selectedRows ( ) ; <nl> int const size = selection . length ( ) ; <nl> <nl> if ( size > 0 ) <nl> void CSystemControlsWidget : : DeleteSelectedControl ( ) <nl> } <nl> else <nl> { <nl> - text = " Are you sure you want to delete the selected controls and folders ? . " ; <nl> + text = " Are you sure you want to delete the selected controls and folders ? " ; <nl> } <nl> <nl> - CQuestionDialog messageBox ; <nl> - messageBox . SetupQuestion ( " Audio Controls Editor " , text ) ; <nl> + CQuestionDialog * messageBox = new CQuestionDialog ( ) ; <nl> + messageBox - > SetupQuestion ( " Audio Controls Editor " , text ) ; <nl> <nl> - if ( messageBox . Execute ( ) = = QDialogButtonBox : : Yes ) <nl> + if ( messageBox - > Execute ( ) = = QDialogButtonBox : : Yes ) <nl> { <nl> CUndo undo ( " Audio Control Removed " ) ; <nl> <nl> void CSystemControlsWidget : : DeleteSelectedControl ( ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CSystemControlsWidget : : ExecuteControl ( ) <nl> { <nl> - CAudioAsset * pAsset = AudioModelUtils : : GetAssetFromIndex ( m_pControlsTree - > currentIndex ( ) ) ; <nl> + CAudioAsset * pAsset = AudioModelUtils : : GetAssetFromIndex ( m_pTreeView - > currentIndex ( ) ) ; <nl> <nl> - if ( pAsset & & pAsset - > GetType ( ) = = eItemType_Trigger ) <nl> + if ( pAsset & & pAsset - > GetType ( ) = = EItemType : : Trigger ) <nl> { <nl> CAudioControlsEditorPlugin : : ExecuteTrigger ( pAsset - > GetName ( ) ) ; <nl> } <nl> QAbstractItemModel * CSystemControlsWidget : : CreateLibraryModelFromIndex ( QModelInd <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> CAudioAsset * CSystemControlsWidget : : GetSelectedAsset ( ) const <nl> { <nl> - QModelIndex const & index = m_pControlsTree - > currentIndex ( ) ; <nl> + QModelIndex const & index = m_pTreeView - > currentIndex ( ) ; <nl> <nl> if ( index . isValid ( ) ) <nl> { <nl> void CSystemControlsWidget : : SelectNewAsset ( QModelIndex const & parent , int const <nl> { <nl> if ( m_bCreatedFromMenu ) <nl> { <nl> - QModelIndex const & assetIndex = m_pProxyModel - > mapFromSource ( m_pMountedModel - > index ( row , 0 , parent ) ) ; <nl> - m_pControlsTree - > setCurrentIndex ( assetIndex ) ; <nl> - m_pControlsTree - > edit ( assetIndex ) ; <nl> + QModelIndex const & assetIndex = m_pFilterProxyModel - > mapFromSource ( m_pMountingProxyModel - > index ( row , 0 , parent ) ) ; <nl> + m_pTreeView - > setCurrentIndex ( assetIndex ) ; <nl> + m_pTreeView - > edit ( assetIndex ) ; <nl> m_bCreatedFromMenu = false ; <nl> } <nl> else if ( ! CAudioControlsEditorPlugin : : GetAssetsManager ( ) - > IsLoading ( ) ) <nl> { <nl> - QModelIndex const & parentIndex = m_pProxyModel - > mapFromSource ( parent ) ; <nl> - m_pControlsTree - > expand ( parentIndex ) ; <nl> - m_pControlsTree - > setCurrentIndex ( parentIndex ) ; <nl> + QModelIndex const & parentIndex = m_pFilterProxyModel - > mapFromSource ( parent ) ; <nl> + m_pTreeView - > expand ( parentIndex ) ; <nl> + m_pTreeView - > setCurrentIndex ( parentIndex ) ; <nl> } <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - void CSystemControlsWidget : : InitFilterWidget ( ) <nl> + void CSystemControlsWidget : : UpdateCreateButtons ( ) <nl> { <nl> - m_pFiltersLayout = new QVBoxLayout ( ) ; <nl> - m_pFiltersLayout - > setContentsMargins ( 0 , 5 , 0 , 5 ) ; <nl> - <nl> - QCheckBox * pFilterTriggersCheckbox = new QCheckBox ( tr ( " Triggers " ) ) ; <nl> - QObject : : connect ( pFilterTriggersCheckbox , & QCheckBox : : toggled , [ & ] ( bool const bShow ) <nl> - { <nl> - ShowControlType ( eItemType_Trigger , bShow ) ; <nl> - } ) ; <nl> - <nl> - pFilterTriggersCheckbox - > setChecked ( true ) ; <nl> - pFilterTriggersCheckbox - > setToolTip ( tr ( " Show / hide Triggers " ) ) ; <nl> - pFilterTriggersCheckbox - > setIcon ( GetItemTypeIcon ( eItemType_Trigger ) ) ; <nl> - m_pFiltersLayout - > addWidget ( pFilterTriggersCheckbox ) ; <nl> - <nl> - QCheckBox * pFilterParametersCheckbox = new QCheckBox ( tr ( " Parameters " ) ) ; <nl> - QObject : : connect ( pFilterParametersCheckbox , & QCheckBox : : toggled , [ & ] ( bool const bShow ) <nl> - { <nl> - ShowControlType ( eItemType_Parameter , bShow ) ; <nl> - } ) ; <nl> - <nl> - pFilterParametersCheckbox - > setChecked ( true ) ; <nl> - pFilterParametersCheckbox - > setToolTip ( tr ( " Show / hide Parameters " ) ) ; <nl> - pFilterParametersCheckbox - > setIcon ( GetItemTypeIcon ( eItemType_Parameter ) ) ; <nl> - m_pFiltersLayout - > addWidget ( pFilterParametersCheckbox ) ; <nl> + auto const selection = m_pTreeView - > selectionModel ( ) - > selectedRows ( ) ; <nl> <nl> - QCheckBox * pFilterSwitchesCheckbox = new QCheckBox ( tr ( " Switches " ) ) ; <nl> - QObject : : connect ( pFilterSwitchesCheckbox , & QCheckBox : : toggled , [ & ] ( bool const bShow ) <nl> - { <nl> - ShowControlType ( eItemType_Switch , bShow ) ; <nl> - } ) ; <nl> - <nl> - pFilterSwitchesCheckbox - > setChecked ( true ) ; <nl> - pFilterSwitchesCheckbox - > setToolTip ( tr ( " Show / hide Switches " ) ) ; <nl> - pFilterSwitchesCheckbox - > setIcon ( GetItemTypeIcon ( eItemType_Switch ) ) ; <nl> - m_pFiltersLayout - > addWidget ( pFilterSwitchesCheckbox ) ; <nl> - <nl> - QCheckBox * pFilterEnvironmentsCheckbox = new QCheckBox ( tr ( " Environments " ) ) ; <nl> - QObject : : connect ( pFilterEnvironmentsCheckbox , & QCheckBox : : toggled , [ & ] ( bool const bShow ) <nl> + if ( ! selection . isEmpty ( ) ) <nl> { <nl> - ShowControlType ( eItemType_Environment , bShow ) ; <nl> - } ) ; <nl> + QModelIndex const index = m_pTreeView - > currentIndex ( ) ; <nl> <nl> - pFilterEnvironmentsCheckbox - > setChecked ( true ) ; <nl> - pFilterEnvironmentsCheckbox - > setToolTip ( tr ( " Show / hide Environments " ) ) ; <nl> - pFilterEnvironmentsCheckbox - > setIcon ( GetItemTypeIcon ( eItemType_Environment ) ) ; <nl> - m_pFiltersLayout - > addWidget ( pFilterEnvironmentsCheckbox ) ; <nl> - <nl> - QCheckBox * pFilterPreloadsCheckbox = new QCheckBox ( tr ( " Preloads " ) ) ; <nl> - QObject : : connect ( pFilterPreloadsCheckbox , & QCheckBox : : toggled , [ & ] ( bool const bShow ) <nl> - { <nl> - ShowControlType ( eItemType_Preload , bShow ) ; <nl> - } ) ; <nl> + if ( index . isValid ( ) ) <nl> + { <nl> + CAudioAsset * const pAsset = AudioModelUtils : : GetAssetFromIndex ( index ) ; <nl> <nl> - pFilterPreloadsCheckbox - > setChecked ( true ) ; <nl> - pFilterPreloadsCheckbox - > setToolTip ( tr ( " Show / hide Preloads " ) ) ; <nl> - pFilterPreloadsCheckbox - > setIcon ( GetItemTypeIcon ( eItemType_Preload ) ) ; <nl> - m_pFiltersLayout - > addWidget ( pFilterPreloadsCheckbox ) ; <nl> + if ( pAsset ! = nullptr ) <nl> + { <nl> + EItemType const itemType = pAsset - > GetType ( ) ; <nl> + bool const bLibraryOrFolder = ( itemType = = EItemType : : Library ) | | ( itemType = = EItemType : : Folder ) ; <nl> + <nl> + m_pCreateFolderAction - > setVisible ( bLibraryOrFolder ) ; <nl> + m_pCreateTriggerAction - > setVisible ( bLibraryOrFolder ) ; <nl> + m_pCreateParameterAction - > setVisible ( bLibraryOrFolder ) ; <nl> + m_pCreateSwitchAction - > setVisible ( bLibraryOrFolder ) ; <nl> + m_pCreateStateAction - > setVisible ( itemType = = EItemType : : Switch ) ; <nl> + m_pCreateEnvironmentAction - > setVisible ( bLibraryOrFolder ) ; <nl> + m_pCreatePreloadAction - > setVisible ( bLibraryOrFolder ) ; <nl> + return ; <nl> + } <nl> + } <nl> + } <nl> <nl> - m_pFilterWidget = QtUtil : : MakeScrollable ( m_pFiltersLayout ) ; <nl> - m_pFilterWidget - > setHidden ( true ) ; <nl> + m_pCreateFolderAction - > setVisible ( false ) ; <nl> + m_pCreateTriggerAction - > setVisible ( false ) ; <nl> + m_pCreateParameterAction - > setVisible ( false ) ; <nl> + m_pCreateSwitchAction - > setVisible ( false ) ; <nl> + m_pCreateStateAction - > setVisible ( false ) ; <nl> + m_pCreateEnvironmentAction - > setVisible ( false ) ; <nl> + m_pCreatePreloadAction - > setVisible ( false ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CSystemControlsWidget : : ResetFilters ( ) <nl> { <nl> - int const filtersCount = m_pFiltersLayout - > count ( ) ; <nl> - <nl> - for ( int i = 0 ; i < filtersCount ; + + i ) <nl> + for ( auto pCheckBox : m_pFilterWidget - > findChildren < QCheckBox * > ( ) ) <nl> { <nl> - QCheckBox * pCheckBox = static_cast < QCheckBox * > ( m_pFiltersLayout - > itemAt ( i ) - > widget ( ) ) ; <nl> - <nl> - if ( pCheckBox ! = nullptr ) <nl> - { <nl> - pCheckBox - > setChecked ( true ) ; <nl> - } <nl> + pCheckBox - > setChecked ( true ) ; <nl> } <nl> <nl> m_pSearchBox - > clear ( ) ; <nl> void CSystemControlsWidget : : ResetFilters ( ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CSystemControlsWidget : : BackupTreeViewStates ( ) <nl> { <nl> - m_pControlsTree - > BackupExpanded ( ) ; <nl> - m_pControlsTree - > BackupSelection ( ) ; <nl> + m_pTreeView - > BackupExpanded ( ) ; <nl> + m_pTreeView - > BackupSelection ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CSystemControlsWidget : : RestoreTreeViewStates ( ) <nl> { <nl> - m_pControlsTree - > RestoreExpanded ( ) ; <nl> - m_pControlsTree - > RestoreSelection ( ) ; <nl> + m_pTreeView - > RestoreExpanded ( ) ; <nl> + m_pTreeView - > RestoreSelection ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> bool CSystemControlsWidget : : IsEditing ( ) const <nl> { <nl> - return m_pControlsTree - > IsEditing ( ) ; <nl> + return m_pTreeView - > IsEditing ( ) ; <nl> } <nl> } / / namespace ACE <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / SystemControlsWidget . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / SystemControlsWidget . h <nl> <nl> <nl> # pragma once <nl> <nl> - # include < QFrame > <nl> - <nl> - # include " AudioAssets . h " <nl> + # include < QWidget > <nl> + # include < ACETypes . h > <nl> # include < CryAudio / IAudioInterfacesCommonData . h > <nl> <nl> - / / Forward declarations <nl> + class QAction ; <nl> + class QHBoxLayout ; <nl> class QVBoxLayout ; <nl> - class QSortFilterProxyModel ; <nl> + class QToolButton ; <nl> class QSearchBox ; <nl> class QAbstractItemModel ; <nl> class CMountingProxyModel ; <nl> <nl> namespace ACE <nl> { <nl> + class CAudioAsset ; <nl> + class CAudioControl ; <nl> class CAudioAssetsManager ; <nl> - class QFilterButton ; <nl> class CSystemControlsModel ; <nl> class CSystemControlsFilterProxyModel ; <nl> class CAudioLibraryModel ; <nl> - class CAdvancedTreeView ; <nl> + class CAudioTreeView ; <nl> <nl> - class CSystemControlsWidget final : public QFrame <nl> + class CSystemControlsWidget final : public QWidget <nl> { <nl> Q_OBJECT <nl> <nl> class CSystemControlsWidget final : public QFrame <nl> void BackupTreeViewStates ( ) ; <nl> void RestoreTreeViewStates ( ) ; <nl> <nl> - private : <nl> - <nl> - / / QObject <nl> - virtual bool eventFilter ( QObject * pObject , QEvent * pEvent ) override ; <nl> - / / ~ QObject <nl> - <nl> - / / Filtering <nl> - void InitFilterWidget ( ) ; <nl> - void ResetFilters ( ) ; <nl> - void ShowControlType ( EItemType type , bool bShow ) ; <nl> - <nl> - CAudioControl * CreateControl ( string const & name , EItemType type , CAudioAsset * pParent ) ; <nl> - CAudioAsset * CreateFolder ( CAudioAsset * pParent ) ; <nl> - <nl> - QAbstractItemModel * CreateLibraryModelFromIndex ( QModelIndex const & sourceIndex ) ; <nl> - CAudioAsset * GetSelectedAsset ( ) const ; <nl> + signals : <nl> <nl> - void SelectNewAsset ( QModelIndex const & parent , int const row ) ; <nl> + void SelectedControlChanged ( ) ; <nl> + void ControlTypeFiltered ( EItemType const type , bool const bShow ) ; <nl> + void StartTextFiltering ( ) ; <nl> + void StopTextFiltering ( ) ; <nl> <nl> private slots : <nl> <nl> void DeleteSelectedControl ( ) ; <nl> void OnContextMenu ( QPoint const & pos ) ; <nl> + void UpdateCreateButtons ( ) ; <nl> <nl> - / / Audio Preview <nl> void ExecuteControl ( ) ; <nl> void StopControlExecution ( ) ; <nl> <nl> - signals : <nl> + private : <nl> <nl> - void SelectedControlChanged ( ) ; <nl> - void ControlTypeFiltered ( EItemType type , bool bShow ) ; <nl> - void StartTextFiltering ( ) ; <nl> - void StopTextFiltering ( ) ; <nl> + / / QObject <nl> + virtual bool eventFilter ( QObject * pObject , QEvent * pEvent ) override ; <nl> + / / ~ QObject <nl> <nl> - private : <nl> + void InitAddControlWidget ( QHBoxLayout * pLayout ) ; <nl> + void InitFilterWidgets ( QVBoxLayout * pMainLayout ) ; <nl> + void InitTypeFilters ( ) ; <nl> + void ResetFilters ( ) ; <nl> + void ShowControlType ( EItemType const type , bool const bShow ) ; <nl> + void SelectNewAsset ( QModelIndex const & parent , int const row ) ; <nl> + <nl> + CAudioControl * CreateControl ( string const & name , EItemType type , CAudioAsset * pParent ) ; <nl> + CAudioAsset * CreateFolder ( CAudioAsset * pParent ) ; <nl> <nl> - CAudioAssetsManager * const m_pAssetsManager ; <nl> + QAbstractItemModel * CreateLibraryModelFromIndex ( QModelIndex const & sourceIndex ) ; <nl> + CAudioAsset * GetSelectedAsset ( ) const ; <nl> + <nl> + CAudioAssetsManager * const m_pAssetsManager ; <nl> <nl> - / / Filtering <nl> QString m_filter ; <nl> QWidget * m_pFilterWidget ; <nl> - QVBoxLayout * m_pFiltersLayout ; <nl> + <nl> + QAction * m_pCreateFolderAction ; <nl> + QAction * m_pCreateTriggerAction ; <nl> + QAction * m_pCreateParameterAction ; <nl> + QAction * m_pCreateSwitchAction ; <nl> + QAction * m_pCreateStateAction ; <nl> + QAction * m_pCreateEnvironmentAction ; <nl> + QAction * m_pCreatePreloadAction ; <nl> <nl> QSearchBox * m_pSearchBox ; <nl> - CAdvancedTreeView * m_pControlsTree ; <nl> - CSystemControlsModel * m_pAssetsModel ; <nl> - CSystemControlsFilterProxyModel * m_pProxyModel ; <nl> + QToolButton * m_pFilterButton ; <nl> + CAudioTreeView * m_pTreeView ; <nl> + CSystemControlsModel * m_pAssetsModel ; <nl> + CSystemControlsFilterProxyModel * m_pFilterProxyModel ; <nl> <nl> - CMountingProxyModel * m_pMountedModel ; <nl> + CMountingProxyModel * m_pMountingProxyModel ; <nl> std : : vector < CAudioLibraryModel * > m_libraryModels ; <nl> bool m_bReloading = false ; <nl> bool m_bCreatedFromMenu = false ; <nl> mmm a / Code / Sandbox / Plugins / EditorAudioControlsEditor / common / ACETypes . h <nl> ppp b / Code / Sandbox / Plugins / EditorAudioControlsEditor / common / ACETypes . h <nl> <nl> <nl> # include < vector > <nl> # include < memory > <nl> + # include < CryCore / CryEnumMacro . h > <nl> <nl> namespace ACE <nl> { <nl> - <nl> - enum EItemType <nl> + enum class EItemType <nl> { <nl> - eItemType_Invalid = - 1 , <nl> + Invalid = - 1 , <nl> <nl> / / controls <nl> - eItemType_Trigger , <nl> - eItemType_Parameter , <nl> - eItemType_Switch , <nl> - eItemType_State , <nl> - eItemType_Environment , <nl> - eItemType_Preload , <nl> - <nl> - eItemType_Folder , <nl> - eItemType_Library , <nl> - eItemType_NumTypes <nl> + Trigger , <nl> + Parameter , <nl> + Switch , <nl> + State , <nl> + Environment , <nl> + Preload , <nl> + <nl> + Folder , <nl> + Library , <nl> + NumTypes <nl> } ; <nl> <nl> - typedef unsigned int ItemType ; <nl> + using ItemType = unsigned int ; <nl> static const ItemType AUDIO_SYSTEM_INVALID_TYPE = 0 ; <nl> <nl> - typedef unsigned int CID ; / / TOdo : do we need this ? <nl> + using CID = unsigned int ; / / TOdo : do we need this ? <nl> static const CID ACE_INVALID_ID = 0 ; <nl> <nl> class IAudioConnection ; <nl> - typedef std : : shared_ptr < IAudioConnection > ConnectionPtr ; <nl> + using ConnectionPtr = std : : shared_ptr < IAudioConnection > ; <nl> <nl> / / available levels where the controls can be stored <nl> struct SScopeInfo <nl> { <nl> - SScopeInfo ( ) { } <nl> - SScopeInfo ( const string & _name , bool _bOnlyLocal ) : name ( _name ) , bOnlyLocal ( _bOnlyLocal ) { } <nl> + SScopeInfo ( ) = default ; <nl> + SScopeInfo ( string const & name_ , bool const bOnlyLocal_ ) : name ( name_ ) , bOnlyLocal ( bOnlyLocal_ ) { } <nl> string name ; <nl> <nl> / / if true , there is a level in the game audio <nl> struct SScopeInfo <nl> } ; <nl> <nl> typedef uint32 Scope ; <nl> - typedef std : : vector < SScopeInfo > ScopeInfoList ; <nl> + using ScopeInfoList = std : : vector < SScopeInfo > ; <nl> <nl> - enum EErrorCode <nl> + enum class EErrorCode <nl> { <nl> - eErrorCode_NoError = 0 , <nl> - eErrorCode_UnkownPlatform = BIT ( 0 ) , <nl> - eErrorCode_NonMatchedActivityRadius = BIT ( 1 ) , <nl> + NoError , <nl> + UnkownPlatform = BIT ( 0 ) , <nl> + NonMatchedActivityRadius = BIT ( 1 ) , <nl> } ; <nl> - <nl> - } <nl> + CRY_CREATE_ENUM_FLAG_OPERATORS ( EErrorCode ) ; <nl> + } / / namespace ACE <nl>
! XO ( Audio ) Replaced CResourceFilterProxyModel with QDeepFilterProxyModel
CRYTEK/CRYENGINE
5cf625038691c3a081024b2ea6fc618b054b2b5c
2017-09-26T09:20:22Z
mmm a / tensorflow / lite / delegates / gpu / common / operations . cc <nl> ppp b / tensorflow / lite / delegates / gpu / common / operations . cc <nl> std : : string ToString ( enum OperationType op ) { <nl> return " batch_normalization " ; <nl> case OperationType : : BATCH_TO_SPACE : <nl> return " batch_to_space " ; <nl> + case OperationType : : BATCHED_MATMUL : <nl> + return " batched_matmul " ; <nl> case OperationType : : CONCAT : <nl> return " concat " ; <nl> case OperationType : : CONST : <nl> OperationType OperationTypeFromString ( const std : : string & name ) { <nl> { " abs " , OperationType : : ABS } , <nl> { " add " , OperationType : : ADD } , <nl> { " batch_normalization " , OperationType : : BATCH_NORMALIZATION } , <nl> + { " batched_matmul " , OperationType : : BATCHED_MATMUL } , <nl> { " concat " , OperationType : : CONCAT } , <nl> { " const " , OperationType : : CONST } , <nl> { " convolution_2d " , OperationType : : CONVOLUTION_2D } , <nl> mmm a / tensorflow / lite / delegates / gpu / common / operations . h <nl> ppp b / tensorflow / lite / delegates / gpu / common / operations . h <nl> enum class OperationType { <nl> ADD , <nl> BATCH_TO_SPACE , <nl> BATCH_NORMALIZATION , <nl> + BATCHED_MATMUL , <nl> CONCAT , <nl> CONST , <nl> CONVOLUTION_2D , <nl> mmm a / tensorflow / lite / delegates / gpu / metal / api . cc <nl> ppp b / tensorflow / lite / delegates / gpu / metal / api . cc <nl> absl : : Status RegisterPrimaryOps ( const GraphFloat32 & graph , const Node * node , <nl> } break ; <nl> case OperationType : : BATCH_NORMALIZATION : <nl> case OperationType : : BATCH_TO_SPACE : <nl> + case OperationType : : BATCHED_MATMUL : <nl> case OperationType : : CONST : <nl> case OperationType : : LSTM : <nl> / / TODO ( b / 162763635 ) : implement MeanStddevNormalization for Metal . <nl>
Added enum for batched matmul operator .
tensorflow/tensorflow
2cea1ba130eb5627d7f5c1af8518054ff000c4ef
2020-09-03T22:01:00Z
mmm a / src / core / hle / service / hid / hid . cpp <nl> ppp b / src / core / hle / service / hid / hid . cpp <nl> void Update ( ) { <nl> <nl> mem - > pad . current_state . hex = state . hex ; <nl> mem - > pad . index = next_pad_index ; <nl> - next_touch_index = ( next_touch_index + 1 ) % mem - > pad . entries . size ( ) ; <nl> + next_pad_index = ( next_pad_index + 1 ) % mem - > pad . entries . size ( ) ; <nl> <nl> / / Get the previous Pad state <nl> u32 last_entry_index = ( mem - > pad . index - 1 ) % mem - > pad . entries . size ( ) ; <nl>
Merge pull request from wwylele / fix_pad
yuzu-emu/yuzu
e07f193aff86987d06107121396f65c6e27c9e8d
2016-03-13T17:04:52Z
new file mode 100644 <nl> index 00000000000 . . e672e539f25 <nl> mmm / dev / null <nl> ppp b / dbms / src / Functions / nextInBlock . cpp <nl> <nl> + # include < Columns / ColumnConst . h > <nl> + # include < DataTypes / getLeastSupertype . h > <nl> + # include < Functions / FunctionFactory . h > <nl> + # include < Functions / IFunction . h > <nl> + # include < IO / WriteHelpers . h > <nl> + <nl> + namespace DB <nl> + { <nl> + namespace ErrorCodes <nl> + { <nl> + extern const int ILLEGAL_COLUMN ; <nl> + extern const int ILLEGAL_TYPE_OF_ARGUMENT ; <nl> + extern const int ARGUMENT_OUT_OF_BOUND ; <nl> + extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH ; <nl> + } <nl> + <nl> + / / Implements function , giving value for column in next row <nl> + / / Example : <nl> + / / | c1 | <nl> + / / | 10 | <nl> + / / | 20 | <nl> + / / SELECT c1 , nextInBlock ( c1 , 1 ) as c2 : <nl> + / / | c1 | c2 | <nl> + / / | 10 | 20 | <nl> + / / | 20 | 0 | <nl> + class FunctionNextInBlock : public IFunction <nl> + { <nl> + public : <nl> + static constexpr auto name = " nextInBlock " ; <nl> + static FunctionPtr create ( const Context & ) { return std : : make_shared < FunctionNextInBlock > ( ) ; } <nl> + <nl> + / / / Get the name of the function . <nl> + String getName ( ) const override { return name ; } <nl> + <nl> + size_t getNumberOfArguments ( ) const override { return 0 ; } <nl> + <nl> + bool isVariadic ( ) const override { return true ; } <nl> + <nl> + bool isDeterministic ( ) const override { return false ; } <nl> + <nl> + bool isDeterministicInScopeOfQuery ( ) const override { return false ; } <nl> + <nl> + DataTypePtr getReturnTypeImpl ( const DataTypes & arguments ) const override <nl> + { <nl> + size_t number_of_arguments = arguments . size ( ) ; <nl> + <nl> + if ( number_of_arguments < 1 | | number_of_arguments > 3 ) <nl> + throw Exception ( <nl> + " Number of arguments for function " + getName ( ) + " doesn ' t match : passed " + toString ( number_of_arguments ) <nl> + + " , should be from 1 to 3 " , <nl> + ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ; <nl> + <nl> + / / second argument must be a positive , constant column <nl> + if ( number_of_arguments = = 2 & & ! isUnsignedInteger ( arguments [ 1 ] ) ) <nl> + throw Exception ( <nl> + " Illegal type " + arguments [ 1 ] - > getName ( ) + " of second argument of function " + getName ( ) <nl> + + " - should be positive integer " , <nl> + ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ; <nl> + <nl> + / / check that default value has supertype with first argument <nl> + if ( number_of_arguments = = 3 ) <nl> + { <nl> + DataTypes types = { arguments [ 0 ] , arguments [ 2 ] } ; <nl> + try <nl> + { <nl> + return getLeastSupertype ( types ) ; <nl> + } <nl> + catch ( const Exception & ) <nl> + { <nl> + throw Exception ( <nl> + " Illegal types of arguments ( " + types [ 0 ] - > getName ( ) + " , " + types [ 1 ] - > getName ( ) <nl> + + " ) " <nl> + " of function " <nl> + + getName ( ) , <nl> + ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ; <nl> + } <nl> + } <nl> + <nl> + return arguments [ 0 ] ; <nl> + } <nl> + <nl> + void executeImpl ( Block & block , const ColumnNumbers & arguments , size_t result , size_t input_rows_count ) override <nl> + { <nl> + size_t offset_value = 1 ; <nl> + <nl> + if ( arguments . size ( ) > 1 ) <nl> + { <nl> + auto offset_column = block . getByPosition ( arguments [ 1 ] ) ; <nl> + if ( ! isColumnConst ( * offset_column . column ) ) <nl> + throw Exception ( " Second argument of function " + getName ( ) + " should be constant " , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ; <nl> + <nl> + Field offset_field = ( * block . getByPosition ( arguments [ 1 ] ) . column ) [ 0 ] ; <nl> + auto raw_value = safeGet < UInt64 > ( offset_field ) ; <nl> + <nl> + if ( raw_value = = 0 ) <nl> + throw Exception ( <nl> + " Second argument of function " + getName ( ) + " should be positive integer , " + toString ( raw_value ) + " given " , <nl> + ErrorCodes : : ARGUMENT_OUT_OF_BOUND ) ; <nl> + <nl> + offset_value = raw_value ; <nl> + } <nl> + <nl> + auto has_column_for_missing = arguments . size ( ) = = 3 ; <nl> + <nl> + DataTypes types = { block . getByPosition ( arguments [ 0 ] ) . type } ; <nl> + if ( has_column_for_missing ) <nl> + { <nl> + types . push_back ( block . getByPosition ( arguments [ 2 ] ) . type ) ; <nl> + } <nl> + const DataTypePtr & result_type = getLeastSupertype ( types ) ; <nl> + <nl> + auto column = result_type - > createColumn ( ) ; <nl> + column - > reserve ( input_rows_count ) ; <nl> + <nl> + auto source_column = block . getByPosition ( arguments [ 0 ] ) . column ; <nl> + <nl> + for ( size_t i = offset_value ; i < input_rows_count ; i + + ) <nl> + { <nl> + column - > insertFrom ( * source_column , i ) ; <nl> + } <nl> + <nl> + if ( has_column_for_missing ) <nl> + { <nl> + auto default_values_column = block . getByPosition ( arguments [ 2 ] ) . column ; <nl> + size_t starting_pos = offset_value > input_rows_count ? 0 : input_rows_count - offset_value ; <nl> + if ( isColumnConst ( * default_values_column ) ) <nl> + { <nl> + Field constant_value = ( * default_values_column ) [ 0 ] ; <nl> + for ( size_t i = starting_pos ; i < input_rows_count ; i + + ) <nl> + { <nl> + column - > insert ( constant_value ) ; <nl> + } <nl> + } <nl> + else <nl> + { <nl> + for ( size_t i = starting_pos ; i < input_rows_count ; i + + ) <nl> + { <nl> + column - > insertFrom ( * default_values_column , i ) ; <nl> + } <nl> + } <nl> + } <nl> + else <nl> + { <nl> + for ( size_t i = 0 ; i < std : : min ( offset_value , input_rows_count ) ; i + + ) <nl> + { <nl> + column - > insertDefault ( ) ; <nl> + } <nl> + } <nl> + <nl> + block . getByPosition ( result ) . column = std : : move ( column ) ; <nl> + } <nl> + } ; <nl> + <nl> + void registerFunctionNextInBlock ( FunctionFactory & factory ) <nl> + { <nl> + factory . registerFunction < FunctionNextInBlock > ( ) ; <nl> + } <nl> + <nl> + } <nl> \ No newline at end of file <nl> mmm a / dbms / src / Functions / registerFunctionsMiscellaneous . cpp <nl> ppp b / dbms / src / Functions / registerFunctionsMiscellaneous . cpp <nl> void registerFunctionBlockSize ( FunctionFactory & ) ; <nl> void registerFunctionBlockNumber ( FunctionFactory & ) ; <nl> void registerFunctionRowNumberInBlock ( FunctionFactory & ) ; <nl> void registerFunctionRowNumberInAllBlocks ( FunctionFactory & ) ; <nl> + void registerFunctionNextInBlock ( FunctionFactory & ) ; <nl> void registerFunctionSleep ( FunctionFactory & ) ; <nl> void registerFunctionSleepEachRow ( FunctionFactory & ) ; <nl> void registerFunctionMaterialize ( FunctionFactory & ) ; <nl> void registerFunctionsMiscellaneous ( FunctionFactory & factory ) <nl> registerFunctionBlockNumber ( factory ) ; <nl> registerFunctionRowNumberInBlock ( factory ) ; <nl> registerFunctionRowNumberInAllBlocks ( factory ) ; <nl> + registerFunctionNextInBlock ( factory ) ; <nl> registerFunctionSleep ( factory ) ; <nl> registerFunctionSleepEachRow ( factory ) ; <nl> registerFunctionMaterialize ( factory ) ; <nl> new file mode 100644 <nl> index 00000000000 . . 860ce6dc1ba <nl> mmm / dev / null <nl> ppp b / dbms / tests / queries / 0_stateless / 00957_next_in_block . reference <nl> <nl> + 0 1 <nl> + 1 0 <nl> + 0 2 <nl> + 1 0 <nl> + 2 0 <nl> + 0 0 <nl> + 1 0 <nl> + 0 2 <nl> + 1 3 <nl> + 2 4 <nl> + 3 1000 <nl> + 4 1000 <nl> new file mode 100644 <nl> index 00000000000 . . 7cbd932cf1a <nl> mmm / dev / null <nl> ppp b / dbms / tests / queries / 0_stateless / 00957_next_in_block . sql <nl> <nl> + - - no arguments <nl> + select nextInBlock ( ) ; - - { serverError 42 } <nl> + - - greater than 3 arguments <nl> + select nextInBlock ( 1 , 2 , 3 , 4 ) ; - - { serverError 42 } <nl> + - - zero offset value <nl> + select nextInBlock ( dummy , 0 ) ; - - { serverError 69 } <nl> + - - negative offset value <nl> + select nextInBlock ( dummy , - 1 ) ; - - { serverError 43 } <nl> + - - non - constant offset value <nl> + select nextInBlock ( dummy , dummy ) ; - - { serverError 43 } <nl> + - - bad default value <nl> + select nextInBlock ( dummy , 1 , ' hello ' ) ; - - { serverError 43 } <nl> + - - single argument test <nl> + select number , nextInBlock ( number ) from numbers ( 2 ) ; <nl> + - - filling by column ' s default value <nl> + select number , nextInBlock ( number , 2 ) from numbers ( 3 ) ; <nl> + - - offset is greater that block - should fill everything with defaults <nl> + select number , nextInBlock ( number , 5 ) from numbers ( 2 ) ; <nl> + - - substitution by constant for missing values <nl> + select number , nextInBlock ( number , 2 , 1000 ) from numbers ( 5 ) ; <nl> + - - substitution by expression <nl> + - - select number , nextInBlock ( number , 2 , number % 2 ) from numbers ( 5 ) ; <nl> \ No newline at end of file <nl>
Implement nextInBlock function
ClickHouse/ClickHouse
8e535a9cb0fe66b44de1be0f5537827aad8d7767
2019-08-06T11:51:13Z
mmm a / caffe2 / utils / math_cpu . cc <nl> ppp b / caffe2 / utils / math_cpu . cc <nl> void CopyMatrix < CPUContext > ( <nl> const int ldb , <nl> CPUContext * / * context * / , <nl> TypeMeta : : TypedCopy copy ) { <nl> - if ( A = = nullptr ) { <nl> + if ( A = = nullptr | | B = = nullptr ) { <nl> return ; <nl> } <nl> if ( lda = = N & & ldb = = N ) { <nl>
fix invalid - null - argument UBSAN error in math_cpu . cc
pytorch/pytorch
b68e2786e09947614272e4840dc85ca6dc2378e0
2018-03-06T08:33:11Z
mmm a / dlib / test / iosockstream . cpp <nl> ppp b / dlib / test / iosockstream . cpp <nl> namespace <nl> { <nl> try <nl> { <nl> - dlog < < LINFO < < " serving connection " ; <nl> + dlog < < LINFO < < " serv1 : serving connection " ; <nl> <nl> std : : string temp ; <nl> in > > temp ; <nl> namespace <nl> <nl> } ; <nl> <nl> + class serv2 : public server_iostream <nl> + { <nl> + virtual void on_connect ( <nl> + std : : istream & , <nl> + std : : ostream & out , <nl> + const std : : string & , <nl> + const std : : string & , <nl> + unsigned short , <nl> + unsigned short , <nl> + uint64 <nl> + ) <nl> + { <nl> + try <nl> + { <nl> + dlog < < LINFO < < " serv2 : serving connection " ; <nl> + <nl> + out < < " one two three four five " ; <nl> + } <nl> + catch ( error & e ) <nl> + { <nl> + error_string = e . what ( ) ; <nl> + } <nl> + <nl> + } <nl> + <nl> + <nl> + public : <nl> + std : : string error_string ; <nl> + <nl> + } ; <nl> + <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> + <nl> + void test1 ( ) <nl> + { <nl> + serv theserv ; <nl> + theserv . set_listening_port ( 12345 ) ; <nl> + theserv . start_async ( ) ; <nl> + <nl> + for ( int i = 0 ; i < 1001 ; + + i ) <nl> + { <nl> + print_spinner ( ) ; <nl> + iosockstream stream ( " localhost : 12345 " ) ; <nl> + <nl> + stream < < " word another " ; <nl> + std : : string temp ; <nl> + stream > > temp ; <nl> + DLIB_TEST ( temp = = " yay " ) ; <nl> + stream > > temp ; <nl> + DLIB_TEST ( temp = = " words " ) ; <nl> + stream < < " yep " ; <nl> + } <nl> + <nl> + / / Just to make sure the server finishes processing the last connection before <nl> + / / we kill it and accidentally trigger a DLIB_TEST ( ) . <nl> + dlib : : sleep ( 500 ) ; <nl> + <nl> + if ( theserv . error_string . size ( ) ! = 0 ) <nl> + throw error ( theserv . error_string ) ; <nl> + } <nl> + <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> + <nl> + void test2 ( ) <nl> + { <nl> + serv2 theserv ; <nl> + theserv . set_listening_port ( 12345 ) ; <nl> + theserv . start_async ( ) ; <nl> + <nl> + for ( int i = 0 ; i < 1001 ; + + i ) <nl> + { <nl> + print_spinner ( ) ; <nl> + iosockstream stream ( " localhost : 12345 " ) ; <nl> + <nl> + std : : string temp ; <nl> + stream > > temp ; DLIB_TEST ( temp = = " one " ) ; <nl> + stream > > temp ; DLIB_TEST ( temp = = " two " ) ; <nl> + stream > > temp ; DLIB_TEST ( temp = = " three " ) ; <nl> + stream > > temp ; DLIB_TEST ( temp = = " four " ) ; <nl> + stream > > temp ; DLIB_TEST ( temp = = " five " ) ; <nl> + } <nl> + } <nl> + <nl> / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> <nl> class test_iosockstream : public tester <nl> namespace <nl> void perform_test ( <nl> ) <nl> { <nl> - serv theserv ; <nl> - theserv . set_listening_port ( 12345 ) ; <nl> - theserv . start_async ( ) ; <nl> - <nl> - for ( int i = 0 ; i < 1001 ; + + i ) <nl> - { <nl> - print_spinner ( ) ; <nl> - iosockstream stream ( " localhost : 12345 " ) ; <nl> - <nl> - stream < < " word another " ; <nl> - std : : string temp ; <nl> - stream > > temp ; <nl> - DLIB_TEST ( temp = = " yay " ) ; <nl> - stream > > temp ; <nl> - DLIB_TEST ( temp = = " words " ) ; <nl> - stream < < " yep " ; <nl> - } <nl> - <nl> - / / Just to make sure the server finishes processing the last connection before <nl> - / / we kill it and accidentally trigger a DLIB_TEST ( ) . <nl> - dlib : : sleep ( 500 ) ; <nl> - <nl> - if ( theserv . error_string . size ( ) ! = 0 ) <nl> - throw error ( theserv . error_string ) ; <nl> + test1 ( ) ; <nl> + test2 ( ) ; <nl> } <nl> } a ; <nl> <nl>
Added more tests
davisking/dlib
da72b57608fdd5b7a7abd9b400e0d8ca4c085728
2012-11-17T21:19:44Z
mmm a / stdlib / public / SDK / Foundation / NSDictionary . swift <nl> ppp b / stdlib / public / SDK / Foundation / NSDictionary . swift <nl> extension Dictionary : _ObjectiveCBridgeable { <nl> let value = Swift . _forceBridgeFromObjectiveC ( <nl> anyValue as AnyObject , Value . self ) <nl> / / FIXME : Log a warning if ` dict ` already had a value for ` key ` <nl> - dict . updateValue ( value , forKey : key ) <nl> + dict [ key ] = value <nl> } ) <nl> result = dict <nl> return <nl>
Use Dictionary ’ s subscript setter rather than updateValue
apple/swift
3982875da02ffa5c0c7510c4c9fd25667d15e090
2018-01-20T00:58:44Z
mmm a / fdbserver / Knobs . cpp <nl> ppp b / fdbserver / Knobs . cpp <nl> ServerKnobs : : ServerKnobs ( bool randomize , ClientKnobs * clientKnobs , bool isSimula <nl> init ( DD_ENABLE_VERBOSE_TRACING , false ) ; if ( randomize & & BUGGIFY ) DD_ENABLE_VERBOSE_TRACING = true ; <nl> init ( DD_SS_FAILURE_VERSIONLAG , 250000000 ) ; <nl> init ( DD_SS_ALLOWED_VERSIONLAG , 200000000 ) ; if ( randomize & & BUGGIFY ) { DD_SS_FAILURE_VERSIONLAG = deterministicRandom ( ) - > randomInt ( 15000000 , 500000000 ) ; DD_SS_ALLOWED_VERSIONLAG = 0 . 75 * DD_SS_FAILURE_VERSIONLAG ; } <nl> - init ( DD_SS_STUCK_TIME_LIMIT , 120 . 0 ) ; if ( randomize & & BUGGIFY ) { DD_SS_STUCK_TIME_LIMIT = 60 . 0 + deterministicRandom ( ) - > random01 ( ) * 60 . 0 ; } <nl> + init ( DD_SS_STUCK_TIME_LIMIT , 300 . 0 ) ; if ( randomize & & BUGGIFY ) { DD_SS_STUCK_TIME_LIMIT = 200 . 0 + deterministicRandom ( ) - > random01 ( ) * 100 . 0 ; } <nl> <nl> / / TeamRemover <nl> init ( TR_FLAG_DISABLE_MACHINE_TEAM_REMOVER , false ) ; if ( randomize & & BUGGIFY ) TR_FLAG_DISABLE_MACHINE_TEAM_REMOVER = deterministicRandom ( ) - > random01 ( ) < 0 . 1 ? true : false ; / / false by default . disable the consistency check when it ' s true <nl>
Adjust knobs .
apple/foundationdb
131ceeae1c2eea37a3413ad075ddbd4ddba92137
2020-04-07T06:45:49Z
mmm a / src / arm / lithium - codegen - arm . cc <nl> ppp b / src / arm / lithium - codegen - arm . cc <nl> void LCodeGen : : DoDeferredInstanceMigration ( LCheckMaps * instr , Register object ) { <nl> PushSafepointRegistersScope scope ( this , Safepoint : : kWithRegisters ) ; <nl> __ push ( object ) ; <nl> __ mov ( cp , Operand : : Zero ( ) ) ; <nl> - __ CallRuntimeSaveDoubles ( Runtime : : kMigrateInstance ) ; <nl> + __ CallRuntimeSaveDoubles ( Runtime : : kTryMigrateInstance ) ; <nl> RecordSafepointWithRegisters ( <nl> instr - > pointer_map ( ) , 1 , Safepoint : : kNoLazyDeopt ) ; <nl> __ StoreToSafepointRegisterSlot ( r0 , scratch0 ( ) ) ; <nl> mmm a / src / ia32 / lithium - codegen - ia32 . cc <nl> ppp b / src / ia32 / lithium - codegen - ia32 . cc <nl> void LCodeGen : : DoDeferredInstanceMigration ( LCheckMaps * instr , Register object ) { <nl> PushSafepointRegistersScope scope ( this ) ; <nl> __ push ( object ) ; <nl> __ xor_ ( esi , esi ) ; <nl> - __ CallRuntimeSaveDoubles ( Runtime : : kMigrateInstance ) ; <nl> + __ CallRuntimeSaveDoubles ( Runtime : : kTryMigrateInstance ) ; <nl> RecordSafepointWithRegisters ( <nl> instr - > pointer_map ( ) , 1 , Safepoint : : kNoLazyDeopt ) ; <nl> <nl> mmm a / src / mips / lithium - codegen - mips . cc <nl> ppp b / src / mips / lithium - codegen - mips . cc <nl> void LCodeGen : : DoDeferredInstanceMigration ( LCheckMaps * instr , Register object ) { <nl> PushSafepointRegistersScope scope ( this , Safepoint : : kWithRegisters ) ; <nl> __ push ( object ) ; <nl> __ mov ( cp , zero_reg ) ; <nl> - __ CallRuntimeSaveDoubles ( Runtime : : kMigrateInstance ) ; <nl> + __ CallRuntimeSaveDoubles ( Runtime : : kTryMigrateInstance ) ; <nl> RecordSafepointWithRegisters ( <nl> instr - > pointer_map ( ) , 1 , Safepoint : : kNoLazyDeopt ) ; <nl> __ StoreToSafepointRegisterSlot ( v0 , scratch0 ( ) ) ; <nl> mmm a / src / runtime . cc <nl> ppp b / src / runtime . cc <nl> RUNTIME_FUNCTION ( MaybeObject * , Runtime_NotifyContextDisposed ) { <nl> } <nl> <nl> <nl> - RUNTIME_FUNCTION ( MaybeObject * , Runtime_MigrateInstance ) { <nl> + RUNTIME_FUNCTION ( MaybeObject * , Runtime_TryMigrateInstance ) { <nl> HandleScope scope ( isolate ) ; <nl> ASSERT ( args . length ( ) = = 1 ) ; <nl> CONVERT_ARG_HANDLE_CHECKED ( Object , object , 0 ) ; <nl> if ( ! object - > IsJSObject ( ) ) return Smi : : FromInt ( 0 ) ; <nl> Handle < JSObject > js_object = Handle < JSObject > : : cast ( object ) ; <nl> if ( ! js_object - > map ( ) - > is_deprecated ( ) ) return Smi : : FromInt ( 0 ) ; <nl> - JSObject : : MigrateInstance ( js_object ) ; <nl> + / / This call must not cause lazy deopts , because it ' s called from deferred <nl> + / / code where we can ' t handle lazy deopts for lack of a suitable bailout <nl> + / / ID . So we just try migration and signal failure if necessary , <nl> + / / which will also trigger a deopt . <nl> + Handle < Object > result = JSObject : : TryMigrateInstance ( js_object ) ; <nl> + if ( result . is_null ( ) ) return Smi : : FromInt ( 0 ) ; <nl> return * object ; <nl> } <nl> <nl> mmm a / src / runtime . h <nl> ppp b / src / runtime . h <nl> namespace internal { <nl> F ( DebugCallbackSupportsStepping , 1 , 1 ) \ <nl> F ( DebugPrepareStepInIfStepping , 1 , 1 ) \ <nl> F ( FlattenString , 1 , 1 ) \ <nl> - F ( MigrateInstance , 1 , 1 ) \ <nl> + F ( TryMigrateInstance , 1 , 1 ) \ <nl> F ( NotifyContextDisposed , 0 , 1 ) \ <nl> F ( MaxSmi , 0 , 1 ) \ <nl> \ <nl> mmm a / src / x64 / lithium - codegen - x64 . cc <nl> ppp b / src / x64 / lithium - codegen - x64 . cc <nl> void LCodeGen : : DoDeferredInstanceMigration ( LCheckMaps * instr , Register object ) { <nl> PushSafepointRegistersScope scope ( this ) ; <nl> __ push ( object ) ; <nl> __ Set ( rsi , 0 ) ; <nl> - __ CallRuntimeSaveDoubles ( Runtime : : kMigrateInstance ) ; <nl> + __ CallRuntimeSaveDoubles ( Runtime : : kTryMigrateInstance ) ; <nl> RecordSafepointWithRegisters ( <nl> instr - > pointer_map ( ) , 1 , Safepoint : : kNoLazyDeopt ) ; <nl> <nl> new file mode 100644 <nl> index 00000000000 . . 51454bf2858 <nl> mmm / dev / null <nl> ppp b / test / mjsunit / regress / regress - crbug - 315252 . js <nl> <nl> + / / Copyright 2014 the V8 project authors . All rights reserved . <nl> + / / Redistribution and use in source and binary forms , with or without <nl> + / / modification , are permitted provided that the following conditions are <nl> + / / met : <nl> + / / <nl> + / / * Redistributions of source code must retain the above copyright <nl> + / / notice , this list of conditions and the following disclaimer . <nl> + / / * Redistributions in binary form must reproduce the above <nl> + / / copyright notice , this list of conditions and the following <nl> + / / disclaimer in the documentation and / or other materials provided <nl> + / / with the distribution . <nl> + / / * Neither the name of Google Inc . nor the names of its <nl> + / / contributors may be used to endorse or promote products derived <nl> + / / from this software without specific prior written permission . <nl> + / / <nl> + / / THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS <nl> + / / " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT <nl> + / / LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR <nl> + / / A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT <nl> + / / OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , <nl> + / / SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT <nl> + / / LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , <nl> + / / DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY <nl> + / / THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT <nl> + / / ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE <nl> + / / OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE . <nl> + <nl> + / / Flags : - - allow - natives - syntax <nl> + <nl> + function f ( a , b , c ) { <nl> + this . a = a ; <nl> + this . b = b ; <nl> + this . c = c ; <nl> + } <nl> + var o3 = new f ( 1 , 2 , 3 . 5 ) ; <nl> + var o4 = new f ( 1 , 2 . 5 , 3 ) ; <nl> + var o1 = new f ( 1 . 5 , 2 , 3 ) ; <nl> + var o2 = new f ( 1 . 5 , 2 , 3 ) ; <nl> + function migrate ( o ) { <nl> + return o . a ; <nl> + } <nl> + / / Use migrate to stabilize o1 , o2 and o4 in [ double , double , smi ] . <nl> + migrate ( o4 ) ; <nl> + migrate ( o1 ) ; <nl> + migrate ( o2 ) ; <nl> + function store_transition ( o ) { <nl> + o . d = 1 ; <nl> + } <nl> + / / Optimize " store_transition " to transition from [ double , double , smi ] to <nl> + / / [ double , double , smi , smi ] . This adds a dependency on the <nl> + / / [ double , double , smi ] map . <nl> + store_transition ( o4 ) ; <nl> + store_transition ( o1 ) ; <nl> + store_transition ( o2 ) ; <nl> + % OptimizeFunctionOnNextCall ( store_transition ) ; <nl> + / / Pass in a deprecated object of format [ smi , smi , double ] . This will migrate <nl> + / / the instance , forcing a merge with [ double , double , smi ] , ending up with <nl> + / / [ double , double , double ] , which deprecates [ double , double , smi ] and <nl> + / / deoptimizes all dependencies of [ double , double , smi ] , including <nl> + / / store_transition itself . <nl> + store_transition ( o3 ) ; <nl>
Turn Runtime_MigrateInstance into Runtime_TryMigrateInstance
v8/v8
1ed94acf0c2ddd063233d6b5f16b09132095ece9
2014-01-14T13:41:09Z
mmm a / src / citra / default_ini . h <nl> ppp b / src / citra / default_ini . h <nl> pad_cleft = <nl> pad_cright = <nl> <nl> [ Core ] <nl> - # The refresh rate for the GPU <nl> - # Defaults to 30 <nl> - gpu_refresh_rate = <nl> - <nl> # The applied frameskip amount . Must be a power of two . <nl> # 0 ( default ) : No frameskip , 1 : x2 frameskip , 2 : x4 frameskip , 3 : x8 frameskip , etc . <nl> frame_skip = <nl>
Merge pull request from linkmauve / remove - dead - option
yuzu-emu/yuzu
a99fb226fe2bf55a60fe29d0820119288c8915a5
2015-07-26T12:18:39Z
mmm a / java / release_notes . txt <nl> ppp b / java / release_notes . txt <nl> <nl> + Nov 11 , 2015 : libphonenumber - 7 . 2 . 1 <nl> + Metadata changes : None <nl> + Fix to 7 . 2 . 0 <nl> + <nl> Nov 10 , 2015 : libphonenumber - 7 . 2 . 0 <nl> Metadata changes : <nl> - Updated phone metadata for region code ( s ) : <nl>
Metadata updates for release 7 . 2 . 1
google/libphonenumber
2a8b33e902bb78d54783d652cb8cd4b3d75e8fd6
2015-11-11T15:25:32Z
mmm a / src / Application . cpp <nl> ppp b / src / Application . cpp <nl> Application : : Application ( int & argc , char * * argv ) : <nl> / / Jump to table if the - t / - - table parameter was set <nl> for ( const QString & t : tableToBrowse ) <nl> m_mainWindow - > switchToBrowseDataTab ( sqlb : : ObjectIdentifier ( " main " , t . toStdString ( ) ) ) ; <nl> + if ( ! tableToBrowse . empty ( ) ) <nl> + m_mainWindow - > refresh ( ) ; <nl> } <nl> } <nl> } <nl>
Refresh table views when using - - table command line option
sqlitebrowser/sqlitebrowser
598dd545e6978a57712b7eef9379ad72f98cd523
2020-08-24T13:33:55Z
mmm a / Marlin / src / feature / babystep . h <nl> ppp b / Marlin / src / feature / babystep . h <nl> class Babystep { <nl> / / apply accumulated babysteps to the axes . <nl> / / <nl> static inline void task ( ) { <nl> - LOOP_L_N ( axis , BS_TODO_AXIS ( Z_AXIS ) ) step_axis ( ( AxisEnum ) axis ) ; <nl> + LOOP_LE_N ( axis , BS_TODO_AXIS ( Z_AXIS ) ) step_axis ( ( AxisEnum ) axis ) ; <nl> } <nl> <nl> private : <nl>
Hotfix for Babystepping
MarlinFirmware/Marlin
730690ea03f61db2f35baf4095b50b4abf1b83bb
2020-02-22T08:55:26Z
mmm a / include / swift / Basic / SourceManager . h <nl> ppp b / include / swift / Basic / SourceManager . h <nl> class SourceManager { <nl> / / / <nl> / / / This respects \ c # sourceLocation directives . <nl> std : : pair < unsigned , unsigned > <nl> - getLineAndColumn ( SourceLoc Loc , unsigned BufferID = 0 ) const { <nl> + getPresumedLineAndColumnForLoc ( SourceLoc Loc , unsigned BufferID = 0 ) const { <nl> assert ( Loc . isValid ( ) ) ; <nl> int LineOffset = getLineOffset ( Loc ) ; <nl> int l , c ; <nl> class SourceManager { <nl> return { LineOffset + l , c } ; <nl> } <nl> <nl> - / / / Returns the real line number for a source location . <nl> + / / / Returns the real line and column for a source location . <nl> / / / <nl> / / / If \ p BufferID is provided , \ p Loc must come from that source buffer . <nl> / / / <nl> / / / This does not respect \ c # sourceLocation directives . <nl> - unsigned getLineNumber ( SourceLoc Loc , unsigned BufferID = 0 ) const { <nl> + std : : pair < unsigned , unsigned > <nl> + getLineAndColumnInBuffer ( SourceLoc Loc , unsigned BufferID = 0 ) const { <nl> assert ( Loc . isValid ( ) ) ; <nl> - return LLVMSourceMgr . FindLineNumber ( Loc . Value , BufferID ) ; <nl> + return LLVMSourceMgr . getLineAndColumn ( Loc . Value , BufferID ) ; <nl> } <nl> <nl> StringRef getEntireTextForBuffer ( unsigned BufferID ) const ; <nl> mmm a / include / swift / SIL / SILRemarkStreamer . h <nl> ppp b / include / swift / SIL / SILRemarkStreamer . h <nl> toRemarkLocation ( const SourceLoc & loc , const SourceManager & srcMgr ) { <nl> <nl> StringRef file = srcMgr . getDisplayNameForLoc ( loc ) ; <nl> unsigned line , col ; <nl> - std : : tie ( line , col ) = srcMgr . getLineAndColumn ( loc ) ; <nl> + std : : tie ( line , col ) = srcMgr . getPresumedLineAndColumnForLoc ( loc ) ; <nl> return llvm : : remarks : : RemarkLocation { file , line , col } ; <nl> } <nl> <nl> mmm a / lib / AST / ASTScopeCreation . cpp <nl> ppp b / lib / AST / ASTScopeCreation . cpp <nl> bool doesRangeableRangeMatch ( const T * x , const SourceManager & SM , <nl> auto const r = getRangeableSourceRange ( x ) ; <nl> if ( r . isInvalid ( ) ) <nl> return false ; <nl> - if ( start & & SM . getLineNumber ( r . Start ) ! = start ) <nl> + if ( start & & SM . getLineAndColumnInBuffer ( r . Start ) . first ! = start ) <nl> return false ; <nl> - if ( end & & SM . getLineNumber ( r . End ) ! = end ) <nl> + if ( end & & SM . getLineAndColumnInBuffer ( r . End ) . first ! = end ) <nl> return false ; <nl> if ( file . empty ( ) ) <nl> return true ; <nl> class LocalizableDeclContextCollector : public ASTWalker { <nl> return ; <nl> auto bufID = SM . findBufferContainingLoc ( loc ) ; <nl> auto f = SM . getIdentifierForBuffer ( bufID ) ; <nl> - auto lin = SM . getLineNumber ( loc ) ; <nl> + auto lin = SM . getLineAndColumnInBuffer ( loc ) . first ; <nl> if ( f . endswith ( file ) & & lin = = line ) <nl> if ( isa < PatternBindingDecl > ( D ) ) <nl> llvm : : errs ( ) < < " * * * catchForDebugging : " < < lin < < " * * * \ n " ; <nl> mmm a / lib / AST / ASTScopePrinting . cpp <nl> ppp b / lib / AST / ASTScopePrinting . cpp <nl> static void printSourceRange ( llvm : : raw_ostream & out , const SourceRange range , <nl> return ; <nl> } <nl> <nl> - auto startLineAndCol = SM . getLineAndColumn ( range . Start ) ; <nl> - auto endLineAndCol = SM . getLineAndColumn ( range . End ) ; <nl> + auto startLineAndCol = SM . getPresumedLineAndColumnForLoc ( range . Start ) ; <nl> + auto endLineAndCol = SM . getPresumedLineAndColumnForLoc ( range . End ) ; <nl> <nl> out < < " [ " < < startLineAndCol . first < < " : " < < startLineAndCol . second < < " - " <nl> < < endLineAndCol . first < < " : " < < endLineAndCol . second < < " ] " ; <nl> mmm a / lib / AST / ASTScopeSourceRange . cpp <nl> ppp b / lib / AST / ASTScopeSourceRange . cpp <nl> bool ASTScopeImpl : : doesRangeMatch ( unsigned start , unsigned end , StringRef file , <nl> return false ; <nl> const auto & SM = getSourceManager ( ) ; <nl> const auto r = getSourceRangeOfScope ( true ) ; <nl> - if ( start & & start ! = SM . getLineNumber ( r . Start ) ) <nl> + if ( start & & start ! = SM . getLineAndColumnInBuffer ( r . Start ) . first ) <nl> return false ; <nl> - if ( end & & end ! = SM . getLineNumber ( r . End ) ) <nl> + if ( end & & end ! = SM . getLineAndColumnInBuffer ( r . End ) . first ) <nl> return false ; <nl> if ( file . empty ( ) ) <nl> return true ; <nl> mmm a / lib / AST / DeclContext . cpp <nl> ppp b / lib / AST / DeclContext . cpp <nl> static unsigned getLineNumber ( DCType * DC ) { <nl> return 0 ; <nl> <nl> const ASTContext & ctx = static_cast < const DeclContext * > ( DC ) - > getASTContext ( ) ; <nl> - return ctx . SourceMgr . getLineAndColumn ( loc ) . first ; <nl> + return ctx . SourceMgr . getPresumedLineAndColumnForLoc ( loc ) . first ; <nl> } <nl> <nl> unsigned DeclContext : : printContext ( raw_ostream & OS , const unsigned indent , <nl> mmm a / lib / AST / GenericSignatureBuilder . cpp <nl> ppp b / lib / AST / GenericSignatureBuilder . cpp <nl> void RequirementSource : : print ( llvm : : raw_ostream & out , <nl> <nl> unsigned bufferID = srcMgr - > findBufferContainingLoc ( loc ) ; <nl> <nl> - auto lineAndCol = srcMgr - > getLineAndColumn ( loc , bufferID ) ; <nl> + auto lineAndCol = srcMgr - > getPresumedLineAndColumnForLoc ( loc , bufferID ) ; <nl> out < < " @ " < < lineAndCol . first < < ' : ' < < lineAndCol . second ; <nl> } ; <nl> <nl> mmm a / lib / AST / IncrementalRanges . cpp <nl> ppp b / lib / AST / IncrementalRanges . cpp <nl> using namespace incremental_ranges ; <nl> <nl> SerializableSourceLocation : : SerializableSourceLocation ( <nl> const SourceLoc loc , const SourceManager & SM ) { <nl> - auto lc = SM . getLineAndColumn ( loc ) ; <nl> + auto lc = SM . getPresumedLineAndColumnForLoc ( loc ) ; <nl> line = lc . first ; <nl> column = lc . second ; <nl> } <nl> mmm a / lib / AST / Module . cpp <nl> ppp b / lib / AST / Module . cpp <nl> SourceFile : : getBasicLocsForDecl ( const Decl * D ) const { <nl> <nl> auto setLineColumn = [ & SM ] ( LineColumn & Home , SourceLoc Loc ) { <nl> if ( Loc . isValid ( ) ) { <nl> - std : : tie ( Home . Line , Home . Column ) = SM . getLineAndColumn ( Loc ) ; <nl> + std : : tie ( Home . Line , Home . Column ) = SM . getPresumedLineAndColumnForLoc ( Loc ) ; <nl> } <nl> } ; <nl> # define SET ( X ) setLineColumn ( Result . X , D - > get # # X ( ) ) ; <nl> mmm a / lib / AST / RawComment . cpp <nl> ppp b / lib / AST / RawComment . cpp <nl> SingleRawComment : : SingleRawComment ( CharSourceRange Range , <nl> const SourceManager & SourceMgr ) <nl> : Range ( Range ) , RawText ( SourceMgr . extractText ( Range ) ) , <nl> Kind ( static_cast < unsigned > ( getCommentKind ( RawText ) ) ) { <nl> - auto StartLineAndColumn = SourceMgr . getLineAndColumn ( Range . getStart ( ) ) ; <nl> + auto StartLineAndColumn = <nl> + SourceMgr . getPresumedLineAndColumnForLoc ( Range . getStart ( ) ) ; <nl> StartLine = StartLineAndColumn . first ; <nl> StartColumn = StartLineAndColumn . second ; <nl> - EndLine = SourceMgr . getLineNumber ( Range . getEnd ( ) ) ; <nl> + EndLine = SourceMgr . getLineAndColumnInBuffer ( Range . getEnd ( ) ) . first ; <nl> } <nl> <nl> SingleRawComment : : SingleRawComment ( StringRef RawText , unsigned StartColumn ) <nl> mmm a / lib / Basic / SourceLoc . cpp <nl> ppp b / lib / Basic / SourceLoc . cpp <nl> void SourceLoc : : printLineAndColumn ( raw_ostream & OS , const SourceManager & SM , <nl> return ; <nl> } <nl> <nl> - auto LineAndCol = SM . getLineAndColumn ( * this , BufferID ) ; <nl> + auto LineAndCol = SM . getPresumedLineAndColumnForLoc ( * this , BufferID ) ; <nl> OS < < " line : " < < LineAndCol . first < < ' : ' < < LineAndCol . second ; <nl> } <nl> <nl> void SourceLoc : : print ( raw_ostream & OS , const SourceManager & SM , <nl> OS < < " line " ; <nl> } <nl> <nl> - auto LineAndCol = SM . getLineAndColumn ( * this , BufferID ) ; <nl> + auto LineAndCol = SM . getPresumedLineAndColumnForLoc ( * this , BufferID ) ; <nl> OS < < ' : ' < < LineAndCol . first < < ' : ' < < LineAndCol . second ; <nl> } <nl> <nl> mmm a / lib / Frontend / DiagnosticVerifier . cpp <nl> ppp b / lib / Frontend / DiagnosticVerifier . cpp <nl> DiagnosticVerifier : : Result DiagnosticVerifier : : verifyFile ( unsigned BufferID ) { <nl> if ( PrevExpectedContinuationLine ) <nl> Expected . LineNo = PrevExpectedContinuationLine ; <nl> else <nl> - Expected . LineNo = SM . getLineAndColumn ( <nl> - BufferStartLoc . getAdvancedLoc ( MatchStart . data ( ) - InputFile . data ( ) ) , <nl> - BufferID ) . first ; <nl> + Expected . LineNo = SM . getPresumedLineAndColumnForLoc ( <nl> + BufferStartLoc . getAdvancedLoc ( MatchStart . data ( ) - <nl> + InputFile . data ( ) ) , <nl> + BufferID ) <nl> + . first ; <nl> Expected . LineNo + = LineOffset ; <nl> <nl> / / Check if the next expected diagnostic should be in the same line . <nl> void DiagnosticVerifier : : handleDiagnostic ( SourceManager & SM , <nl> } <nl> <nl> if ( Info . Loc . isValid ( ) ) { <nl> - const auto lineAndColumn = SM . getLineAndColumn ( Info . Loc ) ; <nl> + const auto lineAndColumn = SM . getPresumedLineAndColumnForLoc ( Info . Loc ) ; <nl> const auto fileName = SM . getDisplayNameForLoc ( Info . Loc ) ; <nl> CapturedDiagnostics . emplace_back ( message , fileName , Info . Kind , Info . Loc , <nl> lineAndColumn . first , lineAndColumn . second , <nl> mmm a / lib / Frontend / PrintingDiagnosticConsumer . cpp <nl> ppp b / lib / Frontend / PrintingDiagnosticConsumer . cpp <nl> namespace { <nl> / / / doesn ' t already exist . <nl> AnnotatedLine & lineForLoc ( SourceLoc Loc ) { <nl> / / FIXME : This call to ` getLineNumber ` is expensive . <nl> - unsigned lineNo = SM . getLineNumber ( Loc ) ; <nl> + unsigned lineNo = SM . getLineAndColumnInBuffer ( Loc ) . first ; <nl> AnnotatedLine newLine ( lineNo , 0 , " " ) ; <nl> auto iter = <nl> std : : lower_bound ( AnnotatedLines . begin ( ) , AnnotatedLines . end ( ) , <nl> namespace { <nl> } ) ; <nl> if ( iter = = AnnotatedLines . end ( ) | | iter - > getLineNumber ( ) ! = lineNo ) { <nl> newLine . LineText = SM . getLineString ( BufferID , lineNo ) ; <nl> - newLine . DisplayLineNumber = SM . getLineAndColumn ( Loc ) . first ; <nl> + newLine . DisplayLineNumber = <nl> + SM . getPresumedLineAndColumnForLoc ( Loc ) . first ; <nl> return * AnnotatedLines . insert ( iter , newLine ) ; <nl> } else { <nl> return * iter ; <nl> namespace { <nl> <nl> void lineRangesForRange ( CharSourceRange Range , <nl> SmallVectorImpl < CharSourceRange > & LineRanges ) { <nl> - unsigned startLineNo = SM . getLineNumber ( Range . getStart ( ) ) ; <nl> - unsigned endLineNo = SM . getLineNumber ( Range . getEnd ( ) ) ; <nl> + unsigned startLineNo = <nl> + SM . getLineAndColumnInBuffer ( Range . getStart ( ) ) . first ; <nl> + unsigned endLineNo = SM . getLineAndColumnInBuffer ( Range . getEnd ( ) ) . first ; <nl> <nl> if ( startLineNo = = endLineNo ) { <nl> LineRanges . push_back ( Range ) ; <nl> namespace { <nl> std : : max ( getPreferredLineNumberIndent ( ) , MinimumLineNumberIndent ) ; <nl> <nl> / / Print the file name at the top of each excerpt . <nl> - auto primaryLineAndColumn = SM . getLineAndColumn ( PrimaryLoc ) ; <nl> + auto primaryLineAndColumn = SM . getPresumedLineAndColumnForLoc ( PrimaryLoc ) ; <nl> Out . changeColor ( ColoredStream : : Colors : : CYAN ) ; <nl> Out < < std : : string ( lineNumberIndent + 1 , ' = ' ) < < " " <nl> < < SM . getDisplayNameForLoc ( PrimaryLoc ) < < " : " <nl> SourceManager : : GetMessage ( SourceLoc Loc , llvm : : SourceMgr : : DiagKind Kind , <nl> R . End . getPointer ( ) - LineStart ) ) ; <nl> } <nl> <nl> - LineAndCol = getLineAndColumn ( Loc ) ; <nl> + LineAndCol = getPresumedLineAndColumnForLoc ( Loc ) ; <nl> } <nl> <nl> return llvm : : SMDiagnostic ( LLVMSourceMgr , Loc . Value , BufferID , <nl> mmm a / lib / Frontend / SerializedDiagnosticConsumer . cpp <nl> ppp b / lib / Frontend / SerializedDiagnosticConsumer . cpp <nl> void SerializedDiagnosticConsumer : : addLocToRecord ( SourceLoc Loc , <nl> <nl> auto bufferId = SM . findBufferContainingLoc ( Loc ) ; <nl> unsigned line , col ; <nl> - std : : tie ( line , col ) = SM . getLineAndColumn ( Loc ) ; <nl> + std : : tie ( line , col ) = SM . getPresumedLineAndColumnForLoc ( Loc ) ; <nl> <nl> Record . push_back ( getEmitFile ( Filename ) ) ; <nl> Record . push_back ( line ) ; <nl> mmm a / lib / IDE / CommentConversion . cpp <nl> ppp b / lib / IDE / CommentConversion . cpp <nl> void CommentToXMLConverter : : visitDocComment ( const DocComment * DC ) { <nl> if ( Loc . isValid ( ) ) { <nl> const auto & SM = D - > getASTContext ( ) . SourceMgr ; <nl> StringRef FileName = SM . getDisplayNameForLoc ( Loc ) ; <nl> - auto LineAndColumn = SM . getLineAndColumn ( Loc ) ; <nl> + auto LineAndColumn = SM . getPresumedLineAndColumnForLoc ( Loc ) ; <nl> OS < < " file = \ " " ; <nl> appendWithXMLEscaping ( OS , FileName ) ; <nl> OS < < " \ " " ; <nl> mmm a / lib / IDE / CompletionInstance . cpp <nl> ppp b / lib / IDE / CompletionInstance . cpp <nl> bool CompletionInstance : : performCachedOperationIfPossible ( <nl> newBufferID = SM . addMemBufferCopy ( sourceText , bufferName ) ; <nl> SM . openVirtualFile ( SM . getLocForBufferStart ( newBufferID ) , <nl> tmpSM . getDisplayNameForLoc ( startLoc ) , <nl> - tmpSM . getLineAndColumn ( startLoc ) . first - 1 ) ; <nl> + tmpSM . getPresumedLineAndColumnForLoc ( startLoc ) . first - <nl> + 1 ) ; <nl> SM . setCodeCompletionPoint ( newBufferID , newOffset ) ; <nl> <nl> / / Construct dummy scopes . We don ' t need to restore the original scope <nl> mmm a / lib / IDE / Formatting . cpp <nl> ppp b / lib / IDE / Formatting . cpp <nl> class FormatContext { <nl> <nl> std : : pair < unsigned , unsigned > indentLineAndColumn ( ) { <nl> if ( InnermostCtx ) <nl> - return SM . getLineAndColumn ( InnermostCtx - > ContextLoc ) ; <nl> + return SM . getPresumedLineAndColumnForLoc ( InnermostCtx - > ContextLoc ) ; <nl> return std : : make_pair ( 0 , 0 ) ; <nl> } <nl> <nl> mmm a / lib / IDE / IDERequests . cpp <nl> ppp b / lib / IDE / IDERequests . cpp <nl> void swift : : simple_display ( llvm : : raw_ostream & out , const CursorInfoOwner & owner ) <nl> return ; <nl> auto & SM = owner . File - > getASTContext ( ) . SourceMgr ; <nl> out < < SM . getIdentifierForBuffer ( * owner . File - > getBufferID ( ) ) ; <nl> - auto LC = SM . getLineAndColumn ( owner . Loc ) ; <nl> + auto LC = SM . getPresumedLineAndColumnForLoc ( owner . Loc ) ; <nl> out < < " : " < < LC . first < < " : " < < LC . second ; <nl> } <nl> <nl> void swift : : ide : : simple_display ( llvm : : raw_ostream & out , <nl> out < < " Resolved cursor info at " ; <nl> auto & SM = info . SF - > getASTContext ( ) . SourceMgr ; <nl> out < < SM . getIdentifierForBuffer ( * info . SF - > getBufferID ( ) ) ; <nl> - auto LC = SM . getLineAndColumn ( info . Loc ) ; <nl> + auto LC = SM . getPresumedLineAndColumnForLoc ( info . Loc ) ; <nl> out < < " : " < < LC . first < < " : " < < LC . second ; <nl> } <nl> <nl> void swift : : simple_display ( llvm : : raw_ostream & out , <nl> return ; <nl> auto & SM = owner . File - > getASTContext ( ) . SourceMgr ; <nl> out < < SM . getIdentifierForBuffer ( * owner . File - > getBufferID ( ) ) ; <nl> - auto SLC = SM . getLineAndColumn ( owner . StartLoc ) ; <nl> - auto ELC = SM . getLineAndColumn ( owner . EndLoc ) ; <nl> + auto SLC = SM . getPresumedLineAndColumnForLoc ( owner . StartLoc ) ; <nl> + auto ELC = SM . getPresumedLineAndColumnForLoc ( owner . EndLoc ) ; <nl> out < < " : ( " < < SLC . first < < " : " < < SLC . second < < " , " <nl> < < ELC . first < < " : " < < ELC . second < < " ) " ; <nl> } <nl> mmm a / lib / IDE / Refactoring . cpp <nl> ppp b / lib / IDE / Refactoring . cpp <nl> getNotableRegions ( StringRef SourceText , unsigned NameOffset , StringRef Name , <nl> unsigned BufferId = Instance - > getPrimarySourceFile ( ) - > getBufferID ( ) . getValue ( ) ; <nl> SourceManager & SM = Instance - > getSourceMgr ( ) ; <nl> SourceLoc NameLoc = SM . getLocForOffset ( BufferId , NameOffset ) ; <nl> - auto LineAndCol = SM . getLineAndColumn ( NameLoc ) ; <nl> + auto LineAndCol = SM . getPresumedLineAndColumnForLoc ( NameLoc ) ; <nl> <nl> UnresolvedLoc UnresoledName { NameLoc , true } ; <nl> <nl> getNotableRegions ( StringRef SourceText , unsigned NameOffset , StringRef Name , <nl> auto Ranges = Renamer . Ranges ; <nl> <nl> std : : vector < NoteRegion > NoteRegions ( Renamer . Ranges . size ( ) ) ; <nl> - std : : transform ( Ranges . begin ( ) , Ranges . end ( ) , NoteRegions . begin ( ) , <nl> - [ & SM ] ( RenameRangeDetail & Detail ) - > NoteRegion { <nl> - auto Start = SM . getLineAndColumn ( Detail . Range . getStart ( ) ) ; <nl> - auto End = SM . getLineAndColumn ( Detail . Range . getEnd ( ) ) ; <nl> - return { Detail . RangeKind , Start . first , Start . second , End . first , End . second , Detail . Index } ; <nl> - } ) ; <nl> + std : : transform ( <nl> + Ranges . begin ( ) , Ranges . end ( ) , NoteRegions . begin ( ) , <nl> + [ & SM ] ( RenameRangeDetail & Detail ) - > NoteRegion { <nl> + auto Start = SM . getPresumedLineAndColumnForLoc ( Detail . Range . getStart ( ) ) ; <nl> + auto End = SM . getPresumedLineAndColumnForLoc ( Detail . Range . getEnd ( ) ) ; <nl> + return { Detail . RangeKind , Start . first , Start . second , <nl> + End . first , End . second , Detail . Index } ; <nl> + } ) ; <nl> <nl> return NoteRegions ; <nl> } <nl> bool RefactoringActionExpandSwitchCases : : performChange ( ) { <nl> InsertRange = CharSourceRange ( SM , RBraceLoc , RBraceLoc ) ; <nl> } <nl> EditorConsumerInsertStream OS ( EditConsumer , SM , InsertRange ) ; <nl> - if ( SM . getLineNumber ( SwitchS - > getLBraceLoc ( ) ) = = <nl> - SM . getLineNumber ( SwitchS - > getRBraceLoc ( ) ) ) { <nl> + if ( SM . getLineAndColumnInBuffer ( SwitchS - > getLBraceLoc ( ) ) . first = = <nl> + SM . getLineAndColumnInBuffer ( SwitchS - > getRBraceLoc ( ) ) . first ) { <nl> OS < < " \ n " ; <nl> } <nl> auto Result = performCasesExpansionInSwitchStmt ( SwitchS , <nl> mmm a / lib / IDE / SyntaxModel . cpp <nl> ppp b / lib / IDE / SyntaxModel . cpp <nl> static bool shouldTreatAsSingleToken ( const SyntaxStructureNode & Node , <nl> / / Avoid passing the individual syntax tokens corresponding to single - line <nl> / / object literal expressions , as they will be reported as a single token . <nl> return Node . Kind = = SyntaxStructureKind : : ObjectLiteralExpression & & <nl> - SM . getLineNumber ( Node . Range . getStart ( ) ) = = <nl> - SM . getLineNumber ( Node . Range . getEnd ( ) ) ; <nl> + SM . getLineAndColumnInBuffer ( Node . Range . getStart ( ) ) . first = = <nl> + SM . getLineAndColumnInBuffer ( Node . Range . getEnd ( ) ) . first ; <nl> } <nl> <nl> std : : pair < bool , Expr * > ModelASTWalker : : walkToExprPre ( Expr * E ) { <nl> mmm a / lib / Index / Index . cpp <nl> ppp b / lib / Index / Index . cpp <nl> class IndexSwiftASTWalker : public SourceEntityWalker { <nl> getLineColAndOffset ( SourceLoc Loc ) { <nl> if ( Loc . isInvalid ( ) ) <nl> return std : : make_tuple ( 0 , 0 , None ) ; <nl> - auto lineAndColumn = SrcMgr . getLineAndColumn ( Loc , BufferID ) ; <nl> + auto lineAndColumn = SrcMgr . getPresumedLineAndColumnForLoc ( Loc , BufferID ) ; <nl> unsigned offset = SrcMgr . getLocOffsetInBuffer ( Loc , BufferID ) ; <nl> return std : : make_tuple ( lineAndColumn . first , lineAndColumn . second , offset ) ; <nl> } <nl> mmm a / lib / Parse / ParseDecl . cpp <nl> ppp b / lib / Parse / ParseDecl . cpp <nl> ParserStatus Parser : : parseLineDirective ( bool isLine ) { <nl> diagnose ( Tok . getLoc ( ) , diag : : extra_tokens_line_directive ) ; <nl> return makeParserError ( ) ; <nl> } <nl> - <nl> - int LineOffset = StartLine - SourceMgr . getLineNumber ( nextLineStartLoc ) ; <nl> - <nl> + <nl> + int LineOffset = <nl> + StartLine - SourceMgr . getLineAndColumnInBuffer ( nextLineStartLoc ) . first ; <nl> + <nl> / / Create a new virtual file for the region started by the # line marker . <nl> bool isNewFile = SourceMgr . openVirtualFile ( nextLineStartLoc , <nl> Filename . getValue ( ) , LineOffset ) ; <nl> mmm a / lib / Parse / ParseExpr . cpp <nl> ppp b / lib / Parse / ParseExpr . cpp <nl> Parser : : parseTrailingClosures ( bool isExprBasic , SourceRange calleeRange , <nl> / / Record the line numbers for the diagnostics below . <nl> / / Note that * do not * move this to after ' parseExprClosure ( ) ' it slows down <nl> / / ' getLineNumber ( ) ' call because of cache in SourceMgr . <nl> - auto origLine = SourceMgr . getLineNumber ( calleeRange . End ) ; <nl> - auto braceLine = SourceMgr . getLineNumber ( braceLoc ) ; <nl> + auto origLine = SourceMgr . getLineAndColumnInBuffer ( calleeRange . End ) . first ; <nl> + auto braceLine = SourceMgr . getLineAndColumnInBuffer ( braceLoc ) . first ; <nl> <nl> ParserStatus result ; <nl> <nl> mmm a / lib / Parse / ParseStmt . cpp <nl> ppp b / lib / Parse / ParseStmt . cpp <nl> ParserResult < Stmt > Parser : : parseStmtReturn ( SourceLoc tryLoc ) { <nl> <nl> / / Issue a warning when the returned expression is on a different line than <nl> / / the return keyword , but both have the same indentation . <nl> - if ( SourceMgr . getLineAndColumn ( ReturnLoc ) . second = = <nl> - SourceMgr . getLineAndColumn ( ExprLoc ) . second ) { <nl> + if ( SourceMgr . getPresumedLineAndColumnForLoc ( ReturnLoc ) . second = = <nl> + SourceMgr . getPresumedLineAndColumnForLoc ( ExprLoc ) . second ) { <nl> diagnose ( ExprLoc , diag : : unindented_code_after_return ) ; <nl> diagnose ( ExprLoc , diag : : indent_expression_to_silence ) ; <nl> } <nl> mmm a / lib / SIL / IR / SILLocation . cpp <nl> ppp b / lib / SIL / IR / SILLocation . cpp <nl> SILLocation : : DebugLoc SILLocation : : decode ( SourceLoc Loc , <nl> DebugLoc DL ; <nl> if ( Loc . isValid ( ) ) { <nl> DL . Filename = SM . getDisplayNameForLoc ( Loc ) ; <nl> - std : : tie ( DL . Line , DL . Column ) = SM . getLineAndColumn ( Loc ) ; <nl> + std : : tie ( DL . Line , DL . Column ) = SM . getPresumedLineAndColumnForLoc ( Loc ) ; <nl> } <nl> return DL ; <nl> } <nl> mmm a / lib / SIL / IR / SILPrinter . cpp <nl> ppp b / lib / SIL / IR / SILPrinter . cpp <nl> class SILPrinter : public SILInstructionVisitor < SILPrinter > { <nl> if ( SILPrintSourceInfo ) { <nl> auto CurSourceLoc = I . getLoc ( ) . getSourceLoc ( ) ; <nl> if ( CurSourceLoc . isValid ( ) ) { <nl> - if ( ! PrevLoc | | SM . getLineNumber ( CurSourceLoc ) > SM . getLineNumber ( PrevLoc - > getSourceLoc ( ) ) ) { <nl> - auto Buffer = SM . findBufferContainingLoc ( CurSourceLoc ) ; <nl> - auto Line = SM . getLineNumber ( CurSourceLoc ) ; <nl> - auto LineLength = SM . getLineLength ( Buffer , Line ) ; <nl> - PrintState . OS < < " / / " < < SM . extractText ( { SM . getLocForLineCol ( Buffer , Line , 0 ) , LineLength . getValueOr ( 0 ) } ) < < <nl> - " \ tSourceLoc : " < < SM . getDisplayNameForLoc ( CurSourceLoc ) < < " : " < < Line < < " \ n " ; <nl> - PrevLoc = I . getLoc ( ) ; <nl> + if ( ! PrevLoc | | <nl> + SM . getLineAndColumnInBuffer ( CurSourceLoc ) . first > <nl> + SM . getLineAndColumnInBuffer ( PrevLoc - > getSourceLoc ( ) ) . first ) { <nl> + auto Buffer = SM . findBufferContainingLoc ( CurSourceLoc ) ; <nl> + auto Line = SM . getLineAndColumnInBuffer ( CurSourceLoc ) . first ; <nl> + auto LineLength = SM . getLineLength ( Buffer , Line ) ; <nl> + PrintState . OS < < " / / " <nl> + < < SM . extractText ( <nl> + { SM . getLocForLineCol ( Buffer , Line , 0 ) , <nl> + LineLength . getValueOr ( 0 ) } ) <nl> + < < " \ tSourceLoc : " <nl> + < < SM . getDisplayNameForLoc ( CurSourceLoc ) < < " : " <nl> + < < Line < < " \ n " ; <nl> + PrevLoc = I . getLoc ( ) ; <nl> } <nl> } <nl> } <nl> mmm a / lib / SIL / IR / SILProfiler . cpp <nl> ppp b / lib / SIL / IR / SILProfiler . cpp <nl> struct CoverageMapping : public ASTWalker { <nl> assert ( Region . hasStartLoc ( ) & & " invalid region " ) ; <nl> assert ( Region . hasEndLoc ( ) & & " incomplete region " ) ; <nl> <nl> - auto Start = SM . getLineAndColumn ( Region . getStartLoc ( ) ) ; <nl> - auto End = SM . getLineAndColumn ( Region . getEndLoc ( ) ) ; <nl> + auto Start = SM . getPresumedLineAndColumnForLoc ( Region . getStartLoc ( ) ) ; <nl> + auto End = SM . getPresumedLineAndColumnForLoc ( Region . getEndLoc ( ) ) ; <nl> assert ( Start . first < = End . first & & " region start and end out of order " ) ; <nl> <nl> Regions . emplace_back ( Start . first , Start . second , End . first , End . second , <nl> mmm a / lib / SILGen / SILGenApply . cpp <nl> ppp b / lib / SILGen / SILGenApply . cpp <nl> RValue SILGenFunction : : emitLiteral ( LiteralExpr * literal , SGFContext C ) { <nl> unsigned Value = 0 ; <nl> if ( Loc . isValid ( ) ) { <nl> Value = magicLiteral - > getKind ( ) = = MagicIdentifierLiteralExpr : : Line <nl> - ? ctx . SourceMgr . getLineAndColumn ( Loc ) . first <nl> - : ctx . SourceMgr . getLineAndColumn ( Loc ) . second ; <nl> + ? ctx . SourceMgr . getPresumedLineAndColumnForLoc ( Loc ) . first <nl> + : ctx . SourceMgr . getPresumedLineAndColumnForLoc ( Loc ) . second ; <nl> } <nl> <nl> auto silTy = SILType : : getBuiltinIntegerLiteralType ( ctx ) ; <nl> mmm a / lib / SILGen / SILGenConvert . cpp <nl> ppp b / lib / SILGen / SILGenConvert . cpp <nl> auto SILGenFunction : : emitSourceLocationArgs ( SourceLoc sourceLoc , <nl> unsigned column = 0 ; <nl> if ( sourceLoc . isValid ( ) ) { <nl> filename = getMagicFileString ( sourceLoc ) ; <nl> - std : : tie ( line , column ) = ctx . SourceMgr . getLineAndColumn ( sourceLoc ) ; <nl> + std : : tie ( line , column ) = <nl> + ctx . SourceMgr . getPresumedLineAndColumnForLoc ( sourceLoc ) ; <nl> } <nl> <nl> bool isASCII = true ; <nl> mmm a / lib / Sema / CSDiagnostics . cpp <nl> ppp b / lib / Sema / CSDiagnostics . cpp <nl> bool ClosureParamDestructuringFailure : : diagnoseAsError ( ) { <nl> / / If this is multi - line closure we ' d have to insert new lines <nl> / / in the suggested ' let ' to keep the structure of the code intact , <nl> / / otherwise just use ' ; ' to keep everything on the same line . <nl> - auto inLine = sourceMgr . getLineNumber ( inLoc ) ; <nl> - auto bodyLine = sourceMgr . getLineNumber ( bodyLoc ) ; <nl> + auto inLine = sourceMgr . getLineAndColumnInBuffer ( inLoc ) . first ; <nl> + auto bodyLine = sourceMgr . getLineAndColumnInBuffer ( bodyLoc ) . first ; <nl> auto isMultiLineClosure = bodyLine > inLine ; <nl> auto indent = <nl> bodyStmts . empty ( ) ? " " : Lexer : : getIndentationForLine ( sourceMgr , bodyLoc ) ; <nl> mmm a / lib / Sema / CSSolver . cpp <nl> ppp b / lib / Sema / CSSolver . cpp <nl> static bool debugConstraintSolverForTarget ( <nl> SourceRange range = target . getSourceRange ( ) ; <nl> if ( range . isValid ( ) ) { <nl> auto charRange = Lexer : : getCharSourceRangeFromSourceRange ( C . SourceMgr , range ) ; <nl> - startLine = C . SourceMgr . getLineNumber ( charRange . getStart ( ) ) ; <nl> - endLine = C . SourceMgr . getLineNumber ( charRange . getEnd ( ) ) ; <nl> + startLine = <nl> + C . SourceMgr . getLineAndColumnInBuffer ( charRange . getStart ( ) ) . first ; <nl> + endLine = C . SourceMgr . getLineAndColumnInBuffer ( charRange . getEnd ( ) ) . first ; <nl> } <nl> <nl> assert ( startLine < = endLine & & " expr ends before it starts ? " ) ; <nl> mmm a / lib / Sema / MiscDiagnostics . cpp <nl> ppp b / lib / Sema / MiscDiagnostics . cpp <nl> static void checkSwitch ( ASTContext & ctx , const SwitchStmt * stmt ) { <nl> continue ; <nl> <nl> auto & SM = ctx . SourceMgr ; <nl> - auto prevLineCol = SM . getLineAndColumn ( prevLoc ) ; <nl> - if ( SM . getLineNumber ( thisLoc ) ! = prevLineCol . first ) <nl> + auto prevLineCol = SM . getPresumedLineAndColumnForLoc ( prevLoc ) ; <nl> + if ( SM . getLineAndColumnInBuffer ( thisLoc ) . first ! = prevLineCol . first ) <nl> continue ; <nl> <nl> ctx . Diags . diagnose ( items [ i ] . getWhereLoc ( ) , diag : : where_on_one_item ) <nl> mmm a / lib / Sema / PCMacro . cpp <nl> ppp b / lib / Sema / PCMacro . cpp <nl> class Instrumenter : InstrumenterBase { <nl> } <nl> <nl> std : : pair < unsigned , unsigned > StartLC = <nl> - Context . SourceMgr . getLineAndColumn ( SR . Start ) ; <nl> + Context . SourceMgr . getPresumedLineAndColumnForLoc ( SR . Start ) ; <nl> <nl> - std : : pair < unsigned , unsigned > EndLC = Context . SourceMgr . getLineAndColumn ( <nl> - Lexer : : getLocForEndOfToken ( Context . SourceMgr , SR . End ) ) ; <nl> + std : : pair < unsigned , unsigned > EndLC = <nl> + Context . SourceMgr . getPresumedLineAndColumnForLoc ( <nl> + Lexer : : getLocForEndOfToken ( Context . SourceMgr , SR . End ) ) ; <nl> <nl> Expr * StartLine = IntegerLiteralExpr : : createFromUnsigned ( Context , StartLC . first ) ; <nl> Expr * EndLine = IntegerLiteralExpr : : createFromUnsigned ( Context , EndLC . first ) ; <nl> class Instrumenter : InstrumenterBase { <nl> } <nl> <nl> std : : pair < unsigned , unsigned > StartLC = <nl> - Context . SourceMgr . getLineAndColumn ( SR . Start ) ; <nl> + Context . SourceMgr . getPresumedLineAndColumnForLoc ( SR . Start ) ; <nl> <nl> - std : : pair < unsigned , unsigned > EndLC = Context . SourceMgr . getLineAndColumn ( <nl> - Lexer : : getLocForEndOfToken ( Context . SourceMgr , SR . End ) ) ; <nl> + std : : pair < unsigned , unsigned > EndLC = <nl> + Context . SourceMgr . getPresumedLineAndColumnForLoc ( <nl> + Lexer : : getLocForEndOfToken ( Context . SourceMgr , SR . End ) ) ; <nl> <nl> Expr * StartLine = IntegerLiteralExpr : : createFromUnsigned ( Context , StartLC . first ) ; <nl> Expr * EndLine = IntegerLiteralExpr : : createFromUnsigned ( Context , EndLC . first ) ; <nl> mmm a / lib / Sema / PlaygroundTransform . cpp <nl> ppp b / lib / Sema / PlaygroundTransform . cpp <nl> class Instrumenter : InstrumenterBase { <nl> } <nl> <nl> std : : pair < unsigned , unsigned > StartLC = <nl> - Context . SourceMgr . getLineAndColumn ( SR . Start ) ; <nl> + Context . SourceMgr . getPresumedLineAndColumnForLoc ( SR . Start ) ; <nl> <nl> - std : : pair < unsigned , unsigned > EndLC = Context . SourceMgr . getLineAndColumn ( <nl> - Lexer : : getLocForEndOfToken ( Context . SourceMgr , SR . End ) ) ; <nl> + std : : pair < unsigned , unsigned > EndLC = <nl> + Context . SourceMgr . getPresumedLineAndColumnForLoc ( <nl> + Lexer : : getLocForEndOfToken ( Context . SourceMgr , SR . End ) ) ; <nl> <nl> Expr * StartLine = IntegerLiteralExpr : : createFromUnsigned ( Context , StartLC . first ) ; <nl> Expr * EndLine = IntegerLiteralExpr : : createFromUnsigned ( Context , EndLC . first ) ; <nl> mmm a / lib / Serialization / SerializeDoc . cpp <nl> ppp b / lib / Serialization / SerializeDoc . cpp <nl> writer . write < uint32_t > ( data . X . Column ) ; <nl> LineColumn getLineColumn ( SourceManager & SM , SourceLoc Loc ) { <nl> LineColumn Result ; <nl> if ( Loc . isValid ( ) ) { <nl> - auto LC = SM . getLineAndColumn ( Loc ) ; <nl> + auto LC = SM . getPresumedLineAndColumnForLoc ( Loc ) ; <nl> Result . Line = LC . first ; <nl> Result . Column = LC . second ; <nl> } <nl> mmm a / lib / SymbolGraphGen / Symbol . cpp <nl> ppp b / lib / SymbolGraphGen / Symbol . cpp <nl> void Symbol : : serializePosition ( StringRef Key , SourceLoc Loc , <nl> SourceManager & SourceMgr , <nl> llvm : : json : : OStream & OS ) const { <nl> / / Note : Line and columns are zero - based in this serialized format . <nl> - auto LineAndColumn = SourceMgr . getLineAndColumn ( Loc ) ; <nl> + auto LineAndColumn = SourceMgr . getPresumedLineAndColumnForLoc ( Loc ) ; <nl> auto Line = LineAndColumn . first - 1 ; <nl> auto Column = LineAndColumn . second - 1 ; <nl> <nl> mmm a / tools / SourceKit / lib / SwiftLang / SwiftDocSupport . cpp <nl> ppp b / tools / SourceKit / lib / SwiftLang / SwiftDocSupport . cpp <nl> class RequestRefactoringEditConsumer : : Implementation { <nl> void accept ( SourceManager & SM , RegionType RegionType , <nl> ArrayRef < Replacement > Replacements ) { <nl> unsigned Start = AllEdits . size ( ) ; <nl> - std : : transform ( Replacements . begin ( ) , Replacements . end ( ) , <nl> - std : : back_inserter ( AllEdits ) , <nl> - [ & ] ( const Replacement & R ) - > Edit { <nl> - std : : pair < unsigned , unsigned > <nl> - Start = SM . getLineAndColumn ( R . Range . getStart ( ) ) , <nl> - End = SM . getLineAndColumn ( R . Range . getEnd ( ) ) ; <nl> - SmallVector < NoteRegion , 4 > SubRanges ; <nl> - auto RawRanges = R . RegionsWorthNote ; <nl> - std : : transform ( RawRanges . begin ( ) , RawRanges . end ( ) , <nl> - std : : back_inserter ( SubRanges ) , <nl> - [ ] ( swift : : ide : : NoteRegion R ) - > SourceKit : : NoteRegion { <nl> - return { <nl> - SwiftLangSupport : : getUIDForRefactoringRangeKind ( R . Kind ) , <nl> - R . StartLine , R . StartColumn , R . EndLine , R . EndColumn , <nl> - R . ArgIndex <nl> - } ; } ) ; <nl> - return { Start . first , Start . second , End . first , <nl> - End . second , R . Text . str ( ) , std : : move ( SubRanges ) } ; <nl> - } ) ; <nl> + std : : transform ( <nl> + Replacements . begin ( ) , Replacements . end ( ) , std : : back_inserter ( AllEdits ) , <nl> + [ & ] ( const Replacement & R ) - > Edit { <nl> + std : : pair < unsigned , unsigned > Start = <nl> + SM . getPresumedLineAndColumnForLoc ( <nl> + R . Range . getStart ( ) ) , <nl> + End = SM . getPresumedLineAndColumnForLoc ( <nl> + R . Range . getEnd ( ) ) ; <nl> + SmallVector < NoteRegion , 4 > SubRanges ; <nl> + auto RawRanges = R . RegionsWorthNote ; <nl> + std : : transform ( <nl> + RawRanges . begin ( ) , RawRanges . end ( ) , std : : back_inserter ( SubRanges ) , <nl> + [ ] ( swift : : ide : : NoteRegion R ) - > SourceKit : : NoteRegion { <nl> + return { SwiftLangSupport : : getUIDForRefactoringRangeKind ( R . Kind ) , <nl> + R . StartLine , <nl> + R . StartColumn , <nl> + R . EndLine , <nl> + R . EndColumn , <nl> + R . ArgIndex } ; <nl> + } ) ; <nl> + return { Start . first , Start . second , End . first , <nl> + End . second , R . Text . str ( ) , std : : move ( SubRanges ) } ; <nl> + } ) ; <nl> unsigned End = AllEdits . size ( ) ; <nl> StartEnds . emplace_back ( Start , End ) ; <nl> UIds . push_back ( SwiftLangSupport : : getUIDForRegionType ( RegionType ) ) ; <nl> class RequestRenameRangeConsumer : : Implementation { <nl> for ( const auto & R : Ranges ) { <nl> SourceKit : : RenameRangeDetail Result ; <nl> std : : tie ( Result . StartLine , Result . StartColumn ) = <nl> - SM . getLineAndColumn ( R . Range . getStart ( ) ) ; <nl> + SM . getPresumedLineAndColumnForLoc ( R . Range . getStart ( ) ) ; <nl> std : : tie ( Result . EndLine , Result . EndColumn ) = <nl> - SM . getLineAndColumn ( R . Range . getEnd ( ) ) ; <nl> + SM . getPresumedLineAndColumnForLoc ( R . Range . getEnd ( ) ) ; <nl> Result . ArgIndex = R . Index ; <nl> Result . Kind = <nl> SwiftLangSupport : : getUIDForRefactoringRangeKind ( R . RangeKind ) ; <nl> mmm a / tools / SourceKit / lib / SwiftLang / SwiftEditor . cpp <nl> ppp b / tools / SourceKit / lib / SwiftLang / SwiftEditor . cpp <nl> void EditorDiagConsumer : : handleDiagnostic ( SourceManager & SM , <nl> <nl> SKInfo . Offset = SM . getLocOffsetInBuffer ( Info . Loc , BufferID ) ; <nl> std : : tie ( SKInfo . Line , SKInfo . Column ) = <nl> - SM . getLineAndColumn ( Info . Loc , BufferID ) ; <nl> + SM . getPresumedLineAndColumnForLoc ( Info . Loc , BufferID ) ; <nl> SKInfo . Filename = SM . getDisplayNameForLoc ( Info . Loc ) . str ( ) ; <nl> <nl> for ( auto R : Info . Ranges ) { <nl> mmm a / tools / SourceKit / lib / SwiftLang / SwiftSourceDocInfo . cpp <nl> ppp b / tools / SourceKit / lib / SwiftLang / SwiftSourceDocInfo . cpp <nl> static void resolveCursor ( <nl> std : : vector < RefactoringKind > Scratch ; <nl> RangeConfig Range ; <nl> Range . BufferId = BufferID ; <nl> - auto Pair = SM . getLineAndColumn ( Loc ) ; <nl> + auto Pair = SM . getPresumedLineAndColumnForLoc ( Loc ) ; <nl> Range . Line = Pair . first ; <nl> Range . Column = Pair . second ; <nl> Range . Length = Length ; <nl> mmm a / tools / swift - ide - test / swift - ide - test . cpp <nl> ppp b / tools / swift - ide - test / swift - ide - test . cpp <nl> class AnnotationPrinter : public SourceEntityWalker { <nl> void printLoc ( SourceLoc Loc , raw_ostream & OS ) { <nl> OS < < ' @ ' ; <nl> if ( Loc . isValid ( ) & & SM . findBufferContainingLoc ( Loc ) = = BufferID ) { <nl> - auto LineCol = SM . getLineAndColumn ( Loc , BufferID ) ; <nl> + auto LineCol = SM . getPresumedLineAndColumnForLoc ( Loc , BufferID ) ; <nl> OS < < LineCol . first < < ' : ' < < LineCol . second ; <nl> } <nl> } <nl> class ASTTypePrinter : public ASTWalker { <nl> SourceCode = SM . extractText ( { SR . Start , <nl> SM . getByteDistance ( SR . Start , EndCharLoc ) } ) ; <nl> unsigned Column ; <nl> - std : : tie ( Line , Column ) = SM . getLineAndColumn ( SR . Start , BufferID ) ; <nl> + std : : tie ( Line , Column ) = <nl> + SM . getPresumedLineAndColumnForLoc ( SR . Start , BufferID ) ; <nl> } <nl> <nl> OS . indent ( IndentLevel * 2 ) ; <nl> class ASTCommentPrinter : public ASTWalker { <nl> if ( auto * VD = dyn_cast < ValueDecl > ( D ) ) { <nl> SourceLoc Loc = D - > getLoc ( ) ; <nl> if ( Loc . isValid ( ) ) { <nl> - auto LineAndColumn = SM . getLineAndColumn ( Loc ) ; <nl> + auto LineAndColumn = SM . getPresumedLineAndColumnForLoc ( Loc ) ; <nl> OS < < SM . getDisplayNameForLoc ( Loc ) <nl> < < " : " < < LineAndColumn . first < < " : " < < LineAndColumn . second < < " : " ; <nl> } else { <nl> class ASTCommentPrinter : public ASTWalker { <nl> } else if ( isa < ExtensionDecl > ( D ) ) { <nl> SourceLoc Loc = D - > getLoc ( ) ; <nl> if ( Loc . isValid ( ) ) { <nl> - auto LineAndColumn = SM . getLineAndColumn ( Loc ) ; <nl> + auto LineAndColumn = SM . getPresumedLineAndColumnForLoc ( Loc ) ; <nl> OS < < SM . getDisplayNameForLoc ( Loc ) <nl> < < " : " < < LineAndColumn . first < < " : " < < LineAndColumn . second < < " : " ; <nl> } else { <nl> class USRPrinter : public SourceEntityWalker { <nl> <nl> void printLoc ( SourceLoc Loc ) { <nl> if ( Loc . isValid ( ) ) { <nl> - auto LineCol = SM . getLineAndColumn ( Loc , BufferID ) ; <nl> + auto LineCol = SM . getPresumedLineAndColumnForLoc ( Loc , BufferID ) ; <nl> OS < < LineCol . first < < ' : ' < < LineCol . second ; <nl> } <nl> } <nl> mmm a / tools / swift - syntax - test / swift - syntax - test . cpp <nl> ppp b / tools / swift - syntax - test / swift - syntax - test . cpp <nl> int dumpEOFSourceLoc ( const char * MainExecutablePath , <nl> <nl> / / To ensure the correctness of position when translated to line & column <nl> / / pair . <nl> - if ( SourceMgr . getLineAndColumn ( EndLoc ) ! = AbPos . getLineAndColumn ( ) ) { <nl> + if ( SourceMgr . getPresumedLineAndColumnForLoc ( EndLoc ) ! = <nl> + AbPos . getLineAndColumn ( ) ) { <nl> llvm : : outs ( ) < < " locations should be identical " ; <nl> return EXIT_FAILURE ; <nl> } <nl> mmm a / unittests / Parse / LexerTests . cpp <nl> ppp b / unittests / Parse / LexerTests . cpp <nl> class StringCaptureDiagnosticConsumer : public DiagnosticConsumer { <nl> llvm : : raw_string_ostream DiagOS ( DiagMsg ) ; <nl> DiagnosticEngine : : formatDiagnosticText ( DiagOS , Info . FormatString , <nl> Info . FormatArgs ) ; <nl> - auto LC = SM . getLineAndColumn ( Info . Loc ) ; <nl> + auto LC = SM . getPresumedLineAndColumnForLoc ( Info . Loc ) ; <nl> std : : ostringstream StrOS ; <nl> StrOS < < LC . first < < " , " < < LC . second < < " : " < < DiagOS . str ( ) ; <nl> messages . push_back ( StrOS . str ( ) ) ; <nl>
[ SourceManager ] Rename line and column APIs for clarity
apple/swift
45bc578ae50797c9b9523209c5b60f45e961e792
2020-05-21T17:54:07Z
mmm a / src / script / sigcache . cpp <nl> ppp b / src / script / sigcache . cpp <nl> <nl> # include < boost / thread . hpp > <nl> <nl> namespace { <nl> - <nl> - / * * <nl> - * We ' re hashing a nonce into the entries themselves , so we don ' t need extra <nl> - * blinding in the set hash computation . <nl> - * <nl> - * This may exhibit platform endian dependent behavior but because these are <nl> - * nonced hashes ( random ) and this state is only ever used locally it is safe . <nl> - * All that matters is local consistency . <nl> - * / <nl> - class SignatureCacheHasher <nl> - { <nl> - public : <nl> - template < uint8_t hash_select > <nl> - uint32_t operator ( ) ( const uint256 & key ) const <nl> - { <nl> - static_assert ( hash_select < 8 , " SignatureCacheHasher only has 8 hashes available . " ) ; <nl> - uint32_t u ; <nl> - std : : memcpy ( & u , key . begin ( ) + 4 * hash_select , 4 ) ; <nl> - return u ; <nl> - } <nl> - } ; <nl> - <nl> / * * <nl> * Valid signature cache , to avoid doing expensive ECDSA signature checking <nl> * twice for every transaction ( once when accepted into memory pool , and <nl> mmm a / src / script / sigcache . h <nl> ppp b / src / script / sigcache . h <nl> static const int64_t MAX_MAX_SIG_CACHE_SIZE = 16384 ; <nl> <nl> class CPubKey ; <nl> <nl> + / * * <nl> + * We ' re hashing a nonce into the entries themselves , so we don ' t need extra <nl> + * blinding in the set hash computation . <nl> + * <nl> + * This may exhibit platform endian dependent behavior but because these are <nl> + * nonced hashes ( random ) and this state is only ever used locally it is safe . <nl> + * All that matters is local consistency . <nl> + * / <nl> + class SignatureCacheHasher <nl> + { <nl> + public : <nl> + template < uint8_t hash_select > <nl> + uint32_t operator ( ) ( const uint256 & key ) const <nl> + { <nl> + static_assert ( hash_select < 8 , " SignatureCacheHasher only has 8 hashes available . " ) ; <nl> + uint32_t u ; <nl> + std : : memcpy ( & u , key . begin ( ) + 4 * hash_select , 4 ) ; <nl> + return u ; <nl> + } <nl> + } ; <nl> + <nl> class CachingTransactionSignatureChecker : public TransactionSignatureChecker <nl> { <nl> private : <nl> mmm a / src / test / cuckoocache_tests . cpp <nl> ppp b / src / test / cuckoocache_tests . cpp <nl> <nl> / / file COPYING or http : / / www . opensource . org / licenses / mit - license . php . <nl> # include < boost / test / unit_test . hpp > <nl> # include " cuckoocache . h " <nl> + # include " script / sigcache . h " <nl> # include " test / test_bitcoin . h " <nl> # include " random . h " <nl> # include < thread > <nl> void insecure_GetRandHash ( uint256 & t ) <nl> * ( ptr + + ) = insecure_rand . rand32 ( ) ; <nl> } <nl> <nl> - / * * Definition copied from / src / script / sigcache . cpp <nl> - * / <nl> - class uint256Hasher <nl> - { <nl> - public : <nl> - template < uint8_t hash_select > <nl> - uint32_t operator ( ) ( const uint256 & key ) const <nl> - { <nl> - static_assert ( hash_select < 8 , " SignatureCacheHasher only has 8 hashes available . " ) ; <nl> - uint32_t u ; <nl> - std : : memcpy ( & u , key . begin ( ) + 4 * hash_select , 4 ) ; <nl> - return u ; <nl> - } <nl> - } ; <nl> <nl> <nl> / * Test that no values not inserted into the cache are read out of it . <nl> class uint256Hasher <nl> BOOST_AUTO_TEST_CASE ( test_cuckoocache_no_fakes ) <nl> { <nl> insecure_rand = FastRandomContext ( true ) ; <nl> - CuckooCache : : cache < uint256 , uint256Hasher > cc { } ; <nl> + CuckooCache : : cache < uint256 , SignatureCacheHasher > cc { } ; <nl> size_t megabytes = 4 ; <nl> cc . setup_bytes ( megabytes < < 20 ) ; <nl> uint256 v ; <nl> BOOST_AUTO_TEST_CASE ( cuckoocache_hit_rate_ok ) <nl> double HitRateThresh = 0 . 98 ; <nl> size_t megabytes = 4 ; <nl> for ( double load = 0 . 1 ; load < 2 ; load * = 2 ) { <nl> - double hits = test_cache < CuckooCache : : cache < uint256 , uint256Hasher > > ( megabytes , load ) ; <nl> + double hits = test_cache < CuckooCache : : cache < uint256 , SignatureCacheHasher > > ( megabytes , load ) ; <nl> BOOST_CHECK ( normalize_hit_rate ( hits , load ) > HitRateThresh ) ; <nl> } <nl> } <nl> void test_cache_erase ( size_t megabytes ) <nl> BOOST_AUTO_TEST_CASE ( cuckoocache_erase_ok ) <nl> { <nl> size_t megabytes = 4 ; <nl> - test_cache_erase < CuckooCache : : cache < uint256 , uint256Hasher > > ( megabytes ) ; <nl> + test_cache_erase < CuckooCache : : cache < uint256 , SignatureCacheHasher > > ( megabytes ) ; <nl> } <nl> <nl> template < typename Cache > <nl> void test_cache_erase_parallel ( size_t megabytes ) <nl> BOOST_AUTO_TEST_CASE ( cuckoocache_erase_parallel_ok ) <nl> { <nl> size_t megabytes = 4 ; <nl> - test_cache_erase_parallel < CuckooCache : : cache < uint256 , uint256Hasher > > ( megabytes ) ; <nl> + test_cache_erase_parallel < CuckooCache : : cache < uint256 , SignatureCacheHasher > > ( megabytes ) ; <nl> } <nl> <nl> <nl> void test_cache_generations ( ) <nl> } <nl> BOOST_AUTO_TEST_CASE ( cuckoocache_generations ) <nl> { <nl> - test_cache_generations < CuckooCache : : cache < uint256 , uint256Hasher > > ( ) ; <nl> + test_cache_generations < CuckooCache : : cache < uint256 , SignatureCacheHasher > > ( ) ; <nl> } <nl> <nl> BOOST_AUTO_TEST_SUITE_END ( ) ; <nl>
Deduplicate SignatureCacheHasher
bitcoin/bitcoin
f9c88079df8b78b8fab75e0903ca395654f2d360
2017-04-12T21:42:41Z
mmm a / tools / depends / target / flatbuffers / Makefile <nl> ppp b / tools / depends / target / flatbuffers / Makefile <nl> DEPS = Makefile <nl> <nl> # lib name , version <nl> LIBNAME = flatbuffers <nl> - VERSION = 1 . 11 . 0 <nl> + VERSION = 1 . 12 . 0 <nl> SOURCE = $ ( LIBNAME ) - $ ( VERSION ) <nl> ARCHIVE = $ ( SOURCE ) . tar . gz <nl> <nl>
[ tools / depends ] bump flatbuffers 1 . 12 . 0
xbmc/xbmc
2264ae144406cd4daf765f2fe29f189692461047
2020-07-28T09:14:19Z
mmm a / jstests / core / distinct1 . js <nl> ppp b / jstests / core / distinct1 . js <nl> res = t . distinct ( " _id " ) ; <nl> assert . eq ( " 1 , 2 " , res . toString ( ) , " C1 " ) ; <nl> res = t . distinct ( " a " , { _id : 1 } ) ; <nl> assert . eq ( " 1 " , res . toString ( ) , " C2 " ) ; <nl> + <nl> + / / Test distinct with db . runCommand <nl> + t . drop ( ) ; <nl> + <nl> + t . save ( { a : 1 , b : 2 } ) ; <nl> + t . save ( { a : 2 , b : 2 } ) ; <nl> + t . save ( { a : 2 , b : 1 } ) ; <nl> + t . save ( { a : 2 , b : 2 } ) ; <nl> + t . save ( { a : 3 , b : 2 } ) ; <nl> + t . save ( { a : 4 , b : 1 } ) ; <nl> + t . save ( { a : 4 , b : 1 } ) ; <nl> + <nl> + res = db . runCommand ( { distinct : " distinct1 " , key : " a " } ) ; <nl> + assert . commandWorked ( res ) ; <nl> + assert . eq ( [ 1 , 2 , 3 , 4 ] , res [ " values " ] , " D1 " ) ; <nl> + res = db . runCommand ( { distinct : " distinct1 " , key : " a " , query : null } ) ; <nl> + assert . commandWorked ( res ) ; <nl> + assert . eq ( [ 1 , 2 , 3 , 4 ] , res [ " values " ] , " D2 " ) ; <nl> + res = db . runCommand ( { distinct : " distinct1 " , key : " a " , query : { b : 2 } } ) ; <nl> + assert . commandWorked ( res ) ; <nl> + assert . eq ( [ 1 , 2 , 3 ] , res [ " values " ] , " D3 " ) ; <nl> + res = db . runCommand ( { distinct : " distinct1 " , key : " a " , query : 1 } ) ; <nl> + assert . commandFailed ( res ) ; <nl> + <nl> + t . drop ( ) ; <nl> mmm a / jstests / core / explain_distinct . js <nl> ppp b / jstests / core / explain_distinct . js <nl> <nl> assert . commandFailed ( runDistinctExplain ( coll , ' b ' , { $ not : 1 } ) ) ; / / Bad query . <nl> assert . commandFailed ( runDistinctExplain ( coll , ' a ' , { $ not : 1 } ) ) ; / / Bad query . <nl> assert . commandFailed ( runDistinctExplain ( coll , ' _id ' , { $ not : 1 } ) ) ; / / Bad query . <nl> - assert . commandFailed ( runDistinctExplain ( coll , ' ' , null ) ) ; / / Bad query . <nl> <nl> / / Ensure that server accepts a distinct command with no ' query ' field . <nl> + assert . commandWorked ( runDistinctExplain ( coll , ' ' , null ) ) ; <nl> assert . commandWorked ( runDistinctExplain ( coll , ' ' ) ) ; <nl> <nl> assert . eq ( [ 1 ] , coll . distinct ( ' b ' ) ) ; <nl> <nl> assert . eq ( 10 , explain . executionStats . nReturned ) ; <nl> assert ( planHasStage ( explain . queryPlanner . winningPlan , " FETCH " ) ) ; <nl> assert ( isIxscan ( explain . queryPlanner . winningPlan ) ) ; <nl> - } ) ( ) ; <nl> \ No newline at end of file <nl> + } ) ( ) ; <nl> mmm a / src / mongo / db / commands / distinct . cpp <nl> ppp b / src / mongo / db / commands / distinct . cpp <nl> class DistinctCommand : public Command { <nl> <nl> / / Extract the query field . If the query field is nonexistent , an empty query is used . <nl> BSONObj query ; <nl> - BSONElement queryElt ; <nl> - auto statusQuery = bsonExtractTypedField ( cmdObj , kQueryField , BSONType : : Object , & queryElt ) ; <nl> - if ( statusQuery . isOK ( ) ) { <nl> - query = queryElt . embeddedObject ( ) ; <nl> - } else if ( statusQuery ! = ErrorCodes : : NoSuchKey ) { <nl> - return { statusQuery } ; <nl> + if ( BSONElement queryElt = cmdObj [ kQueryField ] ) { <nl> + if ( queryElt . type ( ) = = BSONType : : Object ) { <nl> + query = queryElt . embeddedObject ( ) ; <nl> + } else if ( queryElt . type ( ) ! = BSONType : : jstNULL ) { <nl> + return Status ( ErrorCodes : : TypeMismatch , <nl> + str : : stream ( ) < < " \ " " < < kQueryField <nl> + < < " \ " had the wrong type . Expected " <nl> + < < typeName ( BSONType : : Object ) < < " or " <nl> + < < typeName ( BSONType : : jstNULL ) < < " , found " <nl> + < < typeName ( queryElt . type ( ) ) ) ; <nl> + } <nl> } <nl> <nl> auto executor = getExecutorDistinct ( <nl> mmm a / src / mongo / s / commands / commands_public . cpp <nl> ppp b / src / mongo / s / commands / commands_public . cpp <nl> class DistinctCmd : public PublicGridCommand { <nl> <nl> / / Extract the targeting query . <nl> BSONObj targetingQuery ; <nl> - BSONElement queryElt ; <nl> - auto statusQuery = bsonExtractTypedField ( cmdObj , " query " , BSONType : : Object , & queryElt ) ; <nl> - if ( statusQuery . isOK ( ) ) { <nl> - targetingQuery = queryElt . embeddedObject ( ) ; <nl> - } else if ( statusQuery ! = ErrorCodes : : NoSuchKey ) { <nl> - return { statusQuery } ; <nl> + if ( BSONElement queryElt = cmdObj [ " query " ] ) { <nl> + if ( queryElt . type ( ) = = BSONType : : Object ) { <nl> + targetingQuery = queryElt . embeddedObject ( ) ; <nl> + } else if ( queryElt . type ( ) ! = BSONType : : jstNULL ) { <nl> + return Status ( ErrorCodes : : TypeMismatch , <nl> + str : : stream ( ) < < " \ " query \ " had the wrong type . Expected " <nl> + < < typeName ( BSONType : : Object ) < < " or " <nl> + < < typeName ( BSONType : : jstNULL ) < < " , found " <nl> + < < typeName ( queryElt . type ( ) ) ) ; <nl> + } <nl> } <nl> <nl> BSONObjBuilder explainCmdBob ; <nl>
SERVER - 19907 Modified distinct to accept query = null and added jstest
mongodb/mongo
529a9b0e9b9eecf770c9819da4cfcc6a0a5ddd05
2015-09-02T16:01:15Z
mmm a / src / clustering / administration / main / command_line . cc <nl> ppp b / src / clustering / administration / main / command_line . cc <nl> void help_rethinkdb_create ( ) { <nl> } <nl> <nl> void help_rethinkdb_serve ( ) { <nl> - std : : stringstream sstream ; <nl> - sstream < < get_rethinkdb_serve_options_visible ( ) ; <nl> + std : : vector < options : : help_section_t > help_sections ; <nl> + { <nl> + std : : vector < options : : option_t > options ; <nl> + get_rethinkdb_serve_options ( & help_sections , & options ) ; <nl> + } <nl> + <nl> help_pager_t help ; <nl> help . pagef ( " ' rethinkdb serve ' is the actual process for a RethinkDB cluster node . \ n " ) ; <nl> - help . pagef ( " % s \ n " , sstream . str ( ) . c_str ( ) ) ; <nl> + help . pagef ( " % s " , format_help ( help_sections ) . c_str ( ) ) ; <nl> } <nl> <nl> void help_rethinkdb_proxy ( ) { <nl> - std : : stringstream sstream ; <nl> - sstream < < get_rethinkdb_proxy_options_visible ( ) ; <nl> + std : : vector < options : : help_section_t > help_sections ; <nl> + { <nl> + std : : vector < options : : option_t > options ; <nl> + get_rethinkdb_serve_options ( & help_sections , & options ) ; <nl> + } <nl> + <nl> help_pager_t help ; <nl> help . pagef ( " ' rethinkdb proxy ' serves as a proxy to an existing RethinkDB cluster . \ n " ) ; <nl> - help . pagef ( " % s \ n " , sstream . str ( ) . c_str ( ) ) ; <nl> + help . pagef ( " % s " , format_help ( help_sections ) . c_str ( ) ) ; <nl> } <nl> <nl> void help_rethinkdb_import ( ) { <nl> - std : : stringstream sstream ; <nl> - sstream < < get_rethinkdb_import_options ( ) ; <nl> + std : : vector < options : : help_section_t > help_sections ; <nl> + { <nl> + std : : vector < options : : option_t > options ; <nl> + get_rethinkdb_serve_options ( & help_sections , & options ) ; <nl> + } <nl> + <nl> help_pager_t help ; <nl> help . pagef ( " ' rethinkdb import ' imports content from a CSV file . \ n " ) ; <nl> - help . pagef ( " % s \ n " , sstream . str ( ) . c_str ( ) ) ; <nl> + help . pagef ( " % s " , format_help ( help_sections ) . c_str ( ) ) ; <nl> } <nl>
Made help_rethinkdb_serve , help_rethinkdb_proxy , and help_rethinkdb_import use the new parsing system .
rethinkdb/rethinkdb
1501c8a3244e072b9df1f30c8f9300bfc5a88c85
2013-03-05T07:01:10Z
new file mode 100644 <nl> index 0000000000 . . 881617ebc8 <nl> mmm / dev / null <nl> ppp b / html5 / test / unit / shared / BroadcastChannel . js <nl> <nl> + import { expect } from ' chai ' <nl> + import sinon from ' sinon ' <nl> + <nl> + import BroadcastChannel from ' . . / . . / . . / shared / BroadcastChannel ' <nl> + <nl> + describe ( ' BroadcastChannel ' , ( ) = > { <nl> + it ( ' is a function ' , ( ) = > { <nl> + expect ( BroadcastChannel ) . is . an ( ' function ' ) <nl> + } ) <nl> + <nl> + it ( ' has standard APIs ' , ( ) = > { <nl> + const JamesBond = new BroadcastChannel ( ' 007 ' ) <nl> + expect ( JamesBond . name ) . is . an ( ' string ' ) <nl> + expect ( JamesBond . onmessage ) . is . an ( ' null ' ) <nl> + expect ( JamesBond . postMessage ) . is . an ( ' function ' ) <nl> + expect ( JamesBond . close ) . is . an ( ' function ' ) <nl> + <nl> + expect ( JamesBond ) . to . have . ownProperty ( ' name ' ) <nl> + expect ( JamesBond ) . to . have . ownProperty ( ' onmessage ' ) <nl> + expect ( JamesBond ) . not . to . have . ownProperty ( ' postMessage ' ) <nl> + expect ( JamesBond ) . not . to . have . ownProperty ( ' close ' ) <nl> + JamesBond . close ( ) <nl> + } ) <nl> + <nl> + it . skip ( ' inherit APIs ' , ( ) = > { <nl> + const ProfessorX = new BroadcastChannel ( ' Charles ' ) <nl> + expect ( ProfessorX . addEventListener ) . is . an ( ' function ' ) <nl> + expect ( ProfessorX . removeEventListener ) . is . an ( ' function ' ) <nl> + expect ( ProfessorX . dispatchEvent ) . is . an ( ' function ' ) <nl> + } ) <nl> + <nl> + it ( ' name attribute is readonly ' , ( ) = > { <nl> + const Wolverine = new BroadcastChannel ( ' Logan ' ) <nl> + expect ( Wolverine . name ) . to . equal ( ' Logan ' ) <nl> + Wolverine . name = ' Wolverine ' <nl> + expect ( Wolverine . name ) . to . equal ( ' Logan ' ) <nl> + Wolverine . close ( ) <nl> + } ) <nl> + <nl> + describe ( ' basci usage ' , ( ) = > { <nl> + const Hulk = new BroadcastChannel ( ' Avengers ' ) <nl> + const Stack = new BroadcastChannel ( ' Avengers ' ) <nl> + const Steven = new BroadcastChannel ( ' Avengers ' ) <nl> + const Logan = new BroadcastChannel ( ' Mutants ' ) <nl> + const Erik = new BroadcastChannel ( ' Mutants ' ) <nl> + <nl> + beforeEach ( ( ) = > { <nl> + Hulk . onmessage = sinon . spy ( ) <nl> + Stack . onmessage = sinon . spy ( ) <nl> + Steven . onmessage = sinon . spy ( ) <nl> + Logan . onmessage = sinon . spy ( ) <nl> + } ) <nl> + <nl> + afterEach ( ( ) = > { <nl> + Hulk . onmessage = null <nl> + Stack . onmessage = null <nl> + Steven . onmessage = null <nl> + Logan . onmessage = null <nl> + Erik . onmessage = null <nl> + } ) <nl> + <nl> + it ( ' trigger onmessage ' , ( ) = > { <nl> + Hulk . postMessage ( ' Hulk Smash ! ! ! ' ) <nl> + expect ( Hulk . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Logan . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Stack . onmessage . callCount ) . to . be . equal ( 1 ) <nl> + expect ( Steven . onmessage . callCount ) . to . be . equal ( 1 ) <nl> + } ) <nl> + <nl> + it ( ' don \ ' t trigger onmessage itself ' , ( ) = > { <nl> + Logan . postMessage ( ' Any one here ? ' ) <nl> + expect ( Hulk . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Logan . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Stack . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Steven . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + } ) <nl> + <nl> + it ( ' send multi messages ' , ( ) = > { <nl> + Hulk . postMessage ( ' Hulk Smash ! ! ! ' ) <nl> + Logan . postMessage ( ' I will fight you ! ' ) <nl> + Stack . postMessage ( ' whatever ' ) <nl> + Hulk . postMessage ( ' whatever ' ) <nl> + Stack . postMessage ( ' whatever ' ) <nl> + Steven . postMessage ( ' whatever ' ) <nl> + Stack . postMessage ( ' whatever ' ) <nl> + <nl> + expect ( Hulk . onmessage . callCount ) . to . be . equal ( 4 ) <nl> + expect ( Logan . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Stack . onmessage . callCount ) . to . be . equal ( 3 ) <nl> + expect ( Steven . onmessage . callCount ) . to . be . equal ( 5 ) <nl> + } ) <nl> + <nl> + it ( ' send string message ' , ( ) = > { <nl> + Stack . postMessage ( ' I am Iron - Man . ' ) <nl> + <nl> + expect ( Hulk . onmessage . callCount ) . to . be . equal ( 1 ) <nl> + expect ( Steven . onmessage . callCount ) . to . be . equal ( 1 ) <nl> + <nl> + const event = Hulk . onmessage . firstCall . args [ 0 ] <nl> + expect ( event ) . is . an ( ' object ' ) <nl> + expect ( event . data ) . is . a ( ' string ' ) <nl> + expect ( event . data ) . to . be . equal ( ' I am Iron - Man . ' ) <nl> + } ) <nl> + <nl> + it ( ' send object message ' , ( ) = > { <nl> + const message = { <nl> + type : ' SOKOVIA ACCORDS ' , <nl> + approvedCountry : 117 , <nl> + content : ' The Avengers shall no longer be a private organization . ' <nl> + } <nl> + <nl> + Stack . postMessage ( message ) <nl> + <nl> + const event = Steven . onmessage . firstCall . args [ 0 ] <nl> + expect ( event ) . is . an ( ' object ' ) <nl> + expect ( event . data ) . is . a ( ' object ' ) <nl> + expect ( event . data ) . to . deep . equal ( message ) <nl> + } ) <nl> + <nl> + it ( ' close channel ' , ( ) = > { <nl> + Hulk . close ( ) <nl> + <nl> + Steven . postMessage ( ' come to fight ! ' ) <nl> + expect ( Hulk . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Stack . onmessage . callCount ) . to . be . equal ( 1 ) <nl> + expect ( Steven . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + } ) <nl> + <nl> + it ( ' send message after close ' , ( ) = > { <nl> + Hulk . close ( ) <nl> + <nl> + expect ( ( ) = > { Hulk . postMessage ( ' I am leaving . ' ) } ) . to . throw ( Error ) <nl> + <nl> + expect ( Hulk . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Logan . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Stack . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Steven . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + } ) <nl> + <nl> + it ( ' MessageEvent ' , ( ) = > { <nl> + Steven . postMessage ( ' Be Together . ' ) <nl> + <nl> + const event = Stack . onmessage . firstCall . args [ 0 ] <nl> + expect ( event ) . is . an ( ' object ' ) <nl> + expect ( event . data ) . to . be . equal ( ' Be Together . ' ) <nl> + expect ( event . type ) . to . be . equal ( ' message ' ) <nl> + expect ( event . origin ) . to . be . equal ( ' ' ) <nl> + expect ( event . target ) . to . be . null <nl> + expect ( event . timeStamp ) . to . be . a ( ' number ' ) <nl> + } ) <nl> + <nl> + it ( ' invalid usage ' , ( ) = > { <nl> + const stranger = { <nl> + name : ' stranger ' , <nl> + close : Erik . close , <nl> + postMessage : Erik . postMessage <nl> + } <nl> + <nl> + stranger . postMessage ( ' hello world . ' ) <nl> + <nl> + expect ( Hulk . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Logan . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Stack . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + expect ( Steven . onmessage . callCount ) . to . be . equal ( 0 ) <nl> + <nl> + stranger . close ( ) <nl> + } ) <nl> + <nl> + it ( ' close all ' , ( ) = > { <nl> + Hulk . close ( ) <nl> + Stack . close ( ) <nl> + Steven . close ( ) <nl> + Logan . close ( ) <nl> + Erik . close ( ) <nl> + <nl> + / / close again <nl> + expect ( ( ) = > { <nl> + Hulk . close ( ) <nl> + Stack . close ( ) <nl> + Steven . close ( ) <nl> + Logan . close ( ) <nl> + Erik . close ( ) <nl> + } ) . to . not . throw <nl> + } ) <nl> + } ) <nl> + } ) <nl>
+ [ jsfm ] add test case for BroadcastChannel API
apache/incubator-weex
feccd6f5b6c6c793aea2786b0681cf572de8335b
2016-10-31T17:20:16Z
mmm a / swoole_redis_coro . cc <nl> ppp b / swoole_redis_coro . cc <nl> <nl> <nl> # include " php_swoole . h " <nl> # include " swoole_coroutine . h " <nl> + # include " socket . h " <nl> <nl> # include " thirdparty / hiredis / hiredis . h " <nl> # include " thirdparty / hiredis / async . h " <nl> <nl> # include < ext / standard / php_var . h > <nl> <nl> + using namespace swoole ; <nl> + <nl> # define SW_REDIS_COMMAND_ALLOC_ARGS_ARR zval * z_args = ( zval * ) emalloc ( argc * sizeof ( zval ) ) ; <nl> # define SW_REDIS_COMMAND_ARGS_TYPE ( arg ) Z_TYPE ( arg ) <nl> # define SW_REDIS_COMMAND_ARGS_LVAL ( arg ) Z_LVAL ( arg ) <nl> enum swRedisError <nl> SW_REDIS_ERR_ALLOC = - 8 , <nl> } ; <nl> <nl> + enum swRedisOption <nl> + { <nl> + SW_REDIS_OPT_SERIALIZER = 1 , <nl> + SW_REDIS_OPT_PREFIX = 2 , <nl> + SW_REDIS_OPT_READ_TIMEOUT = 3 , <nl> + SW_REDIS_OPT_SCAN = 4 , <nl> + SW_REDIS_OPT_FAILOVER = 5 , <nl> + SW_REDIS_OPT_TCP_KEEPALIVE = 6 , <nl> + SW_REDIS_OPT_COMPRESSION = 7 , <nl> + } ; <nl> + <nl> / * Extended SET argument detection * / <nl> # define IS_EX_ARG ( a ) \ <nl> ( ( a [ 0 ] = = ' e ' | | a [ 0 ] = = ' E ' ) & & ( a [ 1 ] = = ' x ' | | a [ 1 ] = = ' X ' ) & & a [ 2 ] = = ' \ 0 ' ) <nl> static zend_class_entry swoole_redis_coro_ce ; <nl> static zend_class_entry * swoole_redis_coro_ce_ptr ; <nl> static zend_object_handlers swoole_redis_coro_handlers ; <nl> <nl> - ZEND_BEGIN_ARG_INFO_EX ( arginfo_swoole_redis_coro_connect , 0 , 0 , 2 ) <nl> + ZEND_BEGIN_ARG_INFO_EX ( arginfo_swoole_redis_coro_construct , 0 , 0 , 0 ) <nl> + ZEND_ARG_INFO ( 0 , config ) <nl> + ZEND_END_ARG_INFO ( ) <nl> + <nl> + ZEND_BEGIN_ARG_INFO_EX ( arginfo_swoole_redis_coro_connect , 0 , 0 , 1 ) <nl> ZEND_ARG_INFO ( 0 , host ) <nl> ZEND_ARG_INFO ( 0 , port ) <nl> ZEND_ARG_INFO ( 0 , serialize ) <nl> ZEND_END_ARG_INFO ( ) <nl> <nl> - ZEND_BEGIN_ARG_INFO_EX ( arginfo_swoole_redis_coro_construct , 0 , 0 , 0 ) <nl> - ZEND_ARG_INFO ( 0 , config ) <nl> + ZEND_BEGIN_ARG_INFO_EX ( arginfo_swoole_redis_coro_setOption , 0 , 0 , 2 ) <nl> + ZEND_ARG_INFO ( 0 , name ) <nl> + ZEND_ARG_INFO ( 0 , value ) <nl> ZEND_END_ARG_INFO ( ) <nl> <nl> ZEND_BEGIN_ARG_INFO_EX ( arginfo_swoole_redis_coro_void , 0 , 0 , 0 ) <nl> ZEND_END_ARG_INFO ( ) <nl> # define SW_REDIS_CONVERT_ERR ( err ) ( ( err > 0 ? - err : err ) = = SW_REDIS_ERR_IO ? errno : ( err > 0 ? - err : err ) ) <nl> <nl> # define SW_REDIS_COMMAND_CHECK \ <nl> - coro_check ( ) ; \ <nl> + coro_check ( ) ; \ <nl> swRedisClient * redis = ( swRedisClient * ) swoole_get_object ( getThis ( ) ) ; \ <nl> - if ( ! redis | | ! redis - > context ) \ <nl> - { \ <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_CLOSED ) ; \ <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errMsg " ) , " connection is not available . " ) ; \ <nl> - RETURN_FALSE ; \ <nl> + if ( ! redis - > context & & ! swoole_redis_coro_connect ( redis ) ) \ <nl> + { \ <nl> + RETURN_FALSE ; \ <nl> } <nl> <nl> # define SW_REDIS_COMMAND_ARGV_FILL ( str , str_len ) \ <nl> ZEND_END_ARG_INFO ( ) <nl> efree ( argv ) ; \ <nl> } <nl> <nl> - typedef enum <nl> - { <nl> - SW_REDIS_CORO_STATUS_CLOSED , <nl> - SW_REDIS_CORO_STATUS_READY , <nl> - SW_REDIS_CORO_STATUS_WAIT , <nl> - SW_REDIS_CORO_STATUS_DONE , <nl> - } swoole_redis_coro_io_status ; <nl> - <nl> - typedef enum <nl> - { <nl> - SWOOLE_REDIS_CORO_STATE_READY , <nl> - SWOOLE_REDIS_CORO_STATE_SUBSCRIBE , <nl> - SWOOLE_REDIS_CORO_STATE_MULTI , <nl> - SWOOLE_REDIS_CORO_STATE_PIPELINE , <nl> - } swoole_redis_coro_state ; <nl> - <nl> typedef struct <nl> { <nl> redisContext * context ; <nl> - zend_bool defer ; <nl> - swoole_redis_coro_state state ; <nl> - swoole_redis_coro_io_status iowait ; <nl> - zend_bool serialize ; <nl> + std : : string host ; <nl> + uint16_t port ; <nl> + double connect_timeout ; <nl> double timeout ; <nl> - zval * object ; <nl> - zval _object ; <nl> + zend_bool serialize ; <nl> + zend_bool defer ; <nl> + zend_bool internal_connect_failed ; <nl> + zval * zobject ; <nl> + zval _zobject ; <nl> } swRedisClient ; <nl> <nl> typedef struct <nl> enum { SW_REDIS_MODE_MULTI , SW_REDIS_MODE_PIPELINE } ; <nl> <nl> static void swoole_redis_coro_parse_result ( swRedisClient * redis , zval * return_value , redisReply * reply ) ; <nl> <nl> - static bool swoole_redis_coro_close ( zval * zobject ) <nl> + static sw_inline swRedisClient * swoole_get_redis_client ( zval * zobject ) <nl> { <nl> swRedisClient * redis = ( swRedisClient * ) swoole_get_object ( zobject ) ; <nl> - swTraceLog ( SW_TRACE_REDIS_CLIENT , " redis connection closed , fd = % d " , redis - > context - > fd ) ; <nl> + if ( UNEXPECTED ( ! redis ) ) <nl> + { <nl> + swoole_php_fatal_error ( E_ERROR , " you must call Redis constructor first . " ) ; <nl> + } <nl> + return redis ; <nl> + } <nl> + <nl> + static bool swoole_redis_coro_close ( zval * zobject ) <nl> + { <nl> + swRedisClient * redis = swoole_get_redis_client ( zobject ) ; <nl> zend_update_property_bool ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " connected " ) , 0 ) ; <nl> - if ( ! redis | | ! redis - > context ) <nl> + if ( ! redis - > context ) <nl> { <nl> return false ; <nl> } <nl> + swTraceLog ( SW_TRACE_REDIS_CLIENT , " redis connection closed , fd = % d " , redis - > context - > fd ) ; <nl> redisFree ( redis - > context ) ; <nl> redis - > context = NULL ; <nl> return true ; <nl> } <nl> <nl> + static bool swoole_redis_coro_connect ( swRedisClient * redis ) <nl> + { <nl> + zval * zobject = redis - > zobject ; <nl> + redisContext * context ; <nl> + zval * zhost , * zport ; <nl> + char * host ; <nl> + size_t host_len ; <nl> + zend_long port ; <nl> + struct timeval tv ; <nl> + <nl> + if ( redis - > internal_connect_failed ) <nl> + { <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_CLOSED ) ; <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " errMsg " ) , " connection is not available . " ) ; <nl> + return false ; <nl> + } <nl> + <nl> + zhost = sw_zend_read_property ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " host " ) , 0 ) ; <nl> + zport = sw_zend_read_property ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " port " ) , 0 ) ; <nl> + convert_to_string ( zhost ) ; <nl> + convert_to_long ( zport ) ; <nl> + host = Z_STRVAL_P ( zhost ) ; <nl> + host_len = Z_STRLEN_P ( zhost ) ; <nl> + port = Z_LVAL_P ( zport ) ; <nl> + if ( host_len = = 0 ) <nl> + { <nl> + swoole_php_fatal_error ( E_ERROR , " The host is empty . " ) ; <nl> + return false ; <nl> + } <nl> + <nl> + if ( redis - > context ) <nl> + { <nl> + if ( redis - > host . compare ( host ) = = 0 & & redis - > port = = port ) <nl> + { <nl> + return false ; <nl> + } <nl> + else <nl> + { <nl> + swoole_redis_coro_close ( zobject ) ; <nl> + } <nl> + } <nl> + <nl> + php_swoole_check_reactor ( ) ; <nl> + <nl> + if ( redis - > connect_timeout > 0 ) <nl> + { <nl> + tv . tv_sec = redis - > connect_timeout ; <nl> + tv . tv_usec = ( redis - > connect_timeout - ( double ) tv . tv_sec ) * 1000 * 1000 ; <nl> + } <nl> + if ( strncasecmp ( host , ZEND_STRL ( " unix : / " ) ) = = 0 ) <nl> + { <nl> + context = redisConnectUnixWithTimeout ( host + 5 , tv ) ; <nl> + } <nl> + else <nl> + { <nl> + if ( port < = 0 | | port > SW_CLIENT_MAX_PORT ) <nl> + { <nl> + swoole_php_fatal_error ( E_ERROR , " The port " ZEND_LONG_FMT " is invaild . " , port ) ; <nl> + return false ; <nl> + } <nl> + context = redisConnectWithTimeout ( host , ( int ) port , tv ) ; <nl> + } <nl> + <nl> + redis - > context = context ; <nl> + redis - > host = std : : string ( host , host_len ) ; <nl> + redis - > port = port ; <nl> + <nl> + if ( ! context ) <nl> + { <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_ALLOC ) ; <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " errMsg " ) , " cannot allocate redis context . " ) ; <nl> + return false ; <nl> + } <nl> + if ( context - > err ) <nl> + { <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( context - > err ) ) ; <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " errMsg " ) , context - > errstr ) ; <nl> + swoole_redis_coro_close ( zobject ) ; <nl> + redis - > internal_connect_failed = 1 ; <nl> + return false ; <nl> + } <nl> + <nl> + swSetNonBlock ( context - > fd ) ; <nl> + swConnection * conn = swReactor_get ( SwooleG . main_reactor , context - > fd ) ; <nl> + if ( ! conn ) <nl> + { <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_OTHER ) ; <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " errMsg " ) , " Can not found the connection . " ) ; <nl> + swoole_redis_coro_close ( zobject ) ; <nl> + return false ; <nl> + } <nl> + Socket * socket = ( Socket * ) conn - > object ; <nl> + socket - > set_timeout ( redis - > timeout ) ; <nl> + zend_update_property_bool ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " connected " ) , 1 ) ; <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " sock " ) , context - > fd ) ; <nl> + return true ; <nl> + } <nl> + <nl> static void redis_request ( swRedisClient * redis , int argc , char * * argv , size_t * argvlen , zval * return_value ) <nl> { <nl> redisReply * reply = nullptr ; <nl> / / must clear err before request <nl> redis - > context - > err = 0 ; <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errCode " ) , 0 ) ; <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errMsg " ) , " " ) ; <nl> if ( redis - > defer ) <nl> { <nl> if ( redisAppendCommandArgv ( redis - > context , argc , ( const char * * ) argv , ( const size_t * ) argvlen ) = = REDIS_ERR ) <nl> static void redis_request ( swRedisClient * redis , int argc , char * * argv , size_t * a <nl> if ( reply = = nullptr ) <nl> { <nl> _error : <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( redis - > context - > err ) ) ; <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errMsg " ) , redis - > context - > errstr ) ; <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( redis - > context - > err ) ) ; <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errMsg " ) , redis - > context - > errstr ) ; <nl> ZVAL_FALSE ( return_value ) ; <nl> - if ( redis - > context - > err = = REDIS_ERR_EOF ) <nl> + if ( redis - > context - > err = = REDIS_ERR_EOF | | errno = = ETIMEDOUT ) <nl> { <nl> - swoole_redis_coro_close ( redis - > object ) ; <nl> + swoole_redis_coro_close ( redis - > zobject ) ; <nl> } <nl> } <nl> else <nl> { <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errCode " ) , 0 ) ; <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errMsg " ) , " " ) ; <nl> swoole_redis_coro_parse_result ( redis , return_value , reply ) ; <nl> freeReplyObject ( reply ) ; <nl> } <nl> static sw_inline void sw_redis_command_var_key ( INTERNAL_FUNCTION_PARAMETERS , con <nl> else <nl> { <nl> if ( has_timeout & & SW_REDIS_COMMAND_ARGS_TYPE ( z_args [ argc - 2 ] ) ! = IS_LONG ) { <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_OTHER ) ; <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errMsg " ) , " Timeout value must be a LONG " ) ; <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_OTHER ) ; <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errMsg " ) , " Timeout value must be a LONG " ) ; <nl> efree ( z_args ) ; <nl> RETURN_FALSE ; <nl> } <nl> static sw_inline void sw_redis_command_key_str_str ( INTERNAL_FUNCTION_PARAMETERS , <nl> static PHP_METHOD ( swoole_redis_coro , __construct ) ; <nl> static PHP_METHOD ( swoole_redis_coro , __destruct ) ; <nl> static PHP_METHOD ( swoole_redis_coro , connect ) ; <nl> + static PHP_METHOD ( swoole_redis_coro , setOption ) ; <nl> static PHP_METHOD ( swoole_redis_coro , setDefer ) ; <nl> static PHP_METHOD ( swoole_redis_coro , getDefer ) ; <nl> static PHP_METHOD ( swoole_redis_coro , recv ) ; <nl> static const zend_function_entry swoole_redis_coro_methods [ ] = <nl> PHP_ME ( swoole_redis_coro , __construct , arginfo_swoole_redis_coro_construct , ZEND_ACC_PUBLIC ) <nl> PHP_ME ( swoole_redis_coro , __destruct , arginfo_swoole_redis_coro_void , ZEND_ACC_PUBLIC ) <nl> PHP_ME ( swoole_redis_coro , connect , arginfo_swoole_redis_coro_connect , ZEND_ACC_PUBLIC ) <nl> + PHP_ME ( swoole_redis_coro , setOption , arginfo_swoole_redis_coro_setOption , ZEND_ACC_PUBLIC ) <nl> PHP_ME ( swoole_redis_coro , setDefer , NULL , ZEND_ACC_PUBLIC ) <nl> PHP_ME ( swoole_redis_coro , getDefer , NULL , ZEND_ACC_PUBLIC ) <nl> PHP_ME ( swoole_redis_coro , recv , NULL , ZEND_ACC_PUBLIC ) <nl> void swoole_redis_coro_init ( int module_number ) <nl> SWOOLE_SET_CLASS_CLONEABLE ( swoole_redis_coro , zend_class_clone_deny ) ; <nl> SWOOLE_SET_CLASS_UNSET_PROPERTY_HANDLER ( swoole_redis_coro , zend_class_unset_property_deny ) ; <nl> <nl> + zend_declare_property_string ( swoole_redis_coro_ce_ptr , ZEND_STRL ( " host " ) , " " , ZEND_ACC_PUBLIC ) ; <nl> + zend_declare_property_long ( swoole_redis_coro_ce_ptr , ZEND_STRL ( " port " ) , 0 , ZEND_ACC_PUBLIC ) ; <nl> zend_declare_property_null ( swoole_redis_coro_ce_ptr , ZEND_STRL ( " setting " ) , ZEND_ACC_PUBLIC ) ; <nl> - zend_declare_property_null ( swoole_redis_coro_ce_ptr , ZEND_STRL ( " host " ) , ZEND_ACC_PUBLIC ) ; <nl> - zend_declare_property_null ( swoole_redis_coro_ce_ptr , ZEND_STRL ( " port " ) , ZEND_ACC_PUBLIC ) ; <nl> - zend_declare_property_null ( swoole_redis_coro_ce_ptr , ZEND_STRL ( " sock " ) , ZEND_ACC_PUBLIC ) ; <nl> + zend_declare_property_long ( swoole_redis_coro_ce_ptr , ZEND_STRL ( " sock " ) , 0 , ZEND_ACC_PUBLIC ) ; <nl> zend_declare_property_bool ( swoole_redis_coro_ce_ptr , ZEND_STRL ( " connected " ) , 0 , ZEND_ACC_PUBLIC ) ; <nl> zend_declare_property_long ( swoole_redis_coro_ce_ptr , ZEND_STRL ( " errCode " ) , 0 , ZEND_ACC_PUBLIC ) ; <nl> zend_declare_property_string ( swoole_redis_coro_ce_ptr , ZEND_STRL ( " errMsg " ) , " " , ZEND_ACC_PUBLIC ) ; <nl> void swoole_redis_coro_init ( int module_number ) <nl> SWOOLE_DEFINE ( REDIS_ERR_CLOSED ) ; <nl> SWOOLE_DEFINE ( REDIS_ERR_NOAUTH ) ; <nl> SWOOLE_DEFINE ( REDIS_ERR_ALLOC ) ; <nl> + <nl> + / / just support timeout and serialize <nl> + SWOOLE_DEFINE ( REDIS_OPT_READ_TIMEOUT ) ; <nl> + SWOOLE_DEFINE ( REDIS_OPT_SERIALIZER ) ; <nl> } <nl> <nl> static PHP_METHOD ( swoole_redis_coro , __construct ) <nl> static PHP_METHOD ( swoole_redis_coro , __construct ) <nl> RETURN_FALSE ; <nl> } <nl> <nl> - swRedisClient * redis = ( swRedisClient * ) emalloc ( sizeof ( swRedisClient ) ) ; <nl> + swRedisClient * redis = ( swRedisClient * ) swoole_get_object ( getThis ( ) ) ; <nl> + if ( redis ) <nl> + { <nl> + swoole_php_fatal_error ( E_ERROR , " constructor can only be called once . " ) ; <nl> + RETURN_FALSE ; <nl> + } <nl> + <nl> + redis = ( swRedisClient * ) emalloc ( sizeof ( swRedisClient ) ) ; <nl> bzero ( redis , sizeof ( swRedisClient ) ) ; <nl> <nl> - redis - > object = getThis ( ) ; <nl> - sw_copy_to_stack ( redis - > object , redis - > _object ) ; <nl> + redis - > zobject = getThis ( ) ; <nl> + sw_copy_to_stack ( redis - > zobject , redis - > _zobject ) ; <nl> <nl> swoole_set_object ( getThis ( ) , redis ) ; <nl> <nl> - redis - > timeout = SW_REDIS_CONNECT_TIMEOUT ; <nl> + redis - > connect_timeout = SW_REDIS_CONNECT_TIMEOUT ; <nl> + redis - > timeout = COROG . socket_timeout ; <nl> <nl> if ( zset & & ZVAL_IS_ARRAY ( zset ) ) <nl> { <nl> static PHP_METHOD ( swoole_redis_coro , __construct ) <nl> if ( php_swoole_array_get_value ( vht , " timeout " , ztmp ) ) <nl> { <nl> convert_to_double ( ztmp ) ; <nl> + / / For backward compatibility <nl> redis - > timeout = ( double ) Z_DVAL_P ( ztmp ) ; <nl> + if ( redis - > timeout < = 0 ) <nl> + { <nl> + redis - > timeout = ZEND_LONG_MAX ; <nl> + } <nl> + redis - > connect_timeout = redis - > timeout ; <nl> } <nl> } <nl> } <nl> <nl> static PHP_METHOD ( swoole_redis_coro , connect ) <nl> { <nl> - char * host ; <nl> - size_t host_len ; <nl> - long port ; <nl> + zval * zobject = getThis ( ) ; <nl> + swRedisClient * redis = swoole_get_redis_client ( zobject ) ; <nl> + char * host = nullptr ; <nl> + size_t host_len = 0 ; <nl> + long port = 0 ; <nl> zend_bool serialize = 0 ; <nl> + int fd = 0 ; <nl> <nl> coro_check ( ) ; <nl> <nl> - if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " sl | b " , & host , & host_len , & port , & serialize ) = = FAILURE ) <nl> + if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " s | lb " , & host , & host_len , & port , & serialize ) = = FAILURE ) <nl> { <nl> RETURN_FALSE ; <nl> } <nl> <nl> - if ( host_len < = 0 ) <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " host " ) , host ) ; <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , zobject , ZEND_STRL ( " port " ) , port ) ; <nl> + redis - > serialize = serialize ; <nl> + redis - > internal_connect_failed = 0 ; <nl> + <nl> + if ( ( fd = swoole_redis_coro_connect ( redis ) ) > 0 ) <nl> { <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_OTHER ) ; <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errMsg " ) , " host is empty . " ) ; <nl> - RETURN_FALSE ; <nl> + RETURN_TRUE ; <nl> } <nl> - <nl> - swRedisClient * redis = ( swRedisClient * ) swoole_get_object ( getThis ( ) ) ; <nl> - if ( redis - > context ) <nl> + else <nl> { <nl> - swoole_php_fatal_error ( E_WARNING , " connection to the server has already been established . " ) ; <nl> RETURN_FALSE ; <nl> } <nl> + } <nl> <nl> - php_swoole_check_reactor ( ) ; <nl> + static PHP_METHOD ( swoole_redis_coro , setOption ) <nl> + { <nl> + swRedisClient * redis = swoole_get_redis_client ( getThis ( ) ) ; <nl> + zend_long zname ; <nl> + zval * zvalue ; <nl> <nl> - struct timeval tv ; <nl> - if ( redis - > timeout > 0 ) <nl> - { <nl> - tv . tv_sec = redis - > timeout ; <nl> - tv . tv_usec = ( redis - > timeout - ( double ) tv . tv_sec ) * 1000 * 1000 ; <nl> - } <nl> + ZEND_PARSE_PARAMETERS_START ( 2 , 2 ) <nl> + Z_PARAM_LONG ( zname ) <nl> + Z_PARAM_ZVAL ( zvalue ) <nl> + ZEND_PARSE_PARAMETERS_END_EX ( RETURN_FALSE ) ; <nl> <nl> - redis - > serialize = serialize ; <nl> - redisContext * context ; <nl> - if ( strncasecmp ( host , ZEND_STRL ( " unix : / " ) ) = = 0 ) <nl> + switch ( zname ) <nl> { <nl> - context = redisConnectUnixWithTimeout ( host + 5 , tv ) ; <nl> - } <nl> - else <nl> - { <nl> - if ( port < = 1 | | port > 65535 ) <nl> + case SW_REDIS_OPT_READ_TIMEOUT : <nl> + convert_to_double ( zvalue ) ; <nl> + redis - > timeout = ( double ) Z_DVAL_P ( zvalue ) ; <nl> + if ( redis - > timeout < = 0 ) <nl> { <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_OTHER ) ; <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errMsg " ) , " port is invalid . " ) ; <nl> - RETURN_FALSE ; <nl> + redis - > timeout = ZEND_LONG_MAX ; <nl> } <nl> - context = redisConnectWithTimeout ( host , ( int ) port , tv ) ; <nl> - } <nl> - <nl> - if ( context = = NULL ) <nl> - { <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_ALLOC ) ; <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errMsg " ) , " cannot allocate redis context " ) ; <nl> - RETURN_FALSE ; <nl> - } <nl> - <nl> - if ( context - > err ) <nl> - { <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( context - > err ) ) ; <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errMsg " ) , context - > errstr ) ; <nl> - RETURN_FALSE ; <nl> + if ( redis - > context ) <nl> + { <nl> + swConnection * conn = swReactor_get ( SwooleG . main_reactor , redis - > context - > fd ) ; <nl> + if ( conn ) <nl> + { <nl> + Socket * socket = ( Socket * ) conn - > object ; <nl> + socket - > set_timeout ( redis - > timeout ) ; <nl> + } <nl> + } <nl> + break ; <nl> + case SW_REDIS_OPT_SERIALIZER : <nl> + convert_to_boolean ( zvalue ) ; <nl> + redis - > serialize = Z_BVAL_P ( zvalue ) ; <nl> + break ; <nl> + default : <nl> + swoole_php_error ( E_WARNING , " unknown options " ZEND_LONG_FMT " . " , zname ) ; <nl> } <nl> <nl> - swSetNonBlock ( context - > fd ) ; <nl> - redis - > context = context ; <nl> - <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " host " ) , host ) ; <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " port " ) , port ) ; <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " sock " ) , context - > fd ) ; <nl> - zend_update_property_bool ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " connected " ) , 1 ) ; <nl> - <nl> RETURN_TRUE ; <nl> } <nl> <nl> static PHP_METHOD ( swoole_redis_coro , getDefer ) <nl> { <nl> - swRedisClient * redis = ( swRedisClient * ) swoole_get_object ( getThis ( ) ) ; <nl> + swRedisClient * redis = swoole_get_redis_client ( getThis ( ) ) ; <nl> <nl> RETURN_BOOL ( redis - > defer ) ; <nl> } <nl> static PHP_METHOD ( swoole_redis_coro , setDefer ) <nl> RETURN_FALSE ; <nl> } <nl> <nl> - swRedisClient * redis = ( swRedisClient * ) swoole_get_object ( getThis ( ) ) ; <nl> + swRedisClient * redis = swoole_get_redis_client ( getThis ( ) ) ; <nl> redis - > defer = defer ; <nl> <nl> RETURN_TRUE ; <nl> static PHP_METHOD ( swoole_redis_coro , __destruct ) <nl> { <nl> SW_PREVENT_USER_DESTRUCT ; <nl> <nl> - swTraceLog ( SW_TRACE_REDIS_CLIENT , " object_id = % d " , Z_OBJ_HANDLE_P ( getThis ( ) ) ) ; <nl> - <nl> swRedisClient * redis = ( swRedisClient * ) swoole_get_object ( getThis ( ) ) ; <nl> if ( ! redis ) <nl> { <nl> static PHP_METHOD ( swoole_redis_coro , zUnion ) <nl> & & strncasecmp ( Z_STRVAL_P ( value ) , " - inf " , sizeof ( " - inf " ) ) ! = 0 <nl> & & strncasecmp ( Z_STRVAL_P ( value ) , " + inf " , sizeof ( " + inf " ) ) ! = 0 ) <nl> { <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_OTHER ) ; <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errMsg " ) , " Weights must be numeric or ' - inf ' , ' inf ' , ' + inf ' " ) ; <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errCode " ) , SW_REDIS_ERR_OTHER ) ; <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errMsg " ) , " Weights must be numeric or ' - inf ' , ' inf ' , ' + inf ' " ) ; <nl> for ( j = 0 ; j < i ; j + + ) <nl> { <nl> efree ( ( void * ) argv [ j ] ) ; <nl> static PHP_METHOD ( swoole_redis_coro , pSubscribe ) <nl> } <nl> else <nl> { <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( redis - > context - > err ) ) ; <nl> if ( redis - > context - > err = = REDIS_ERR_EOF ) <nl> { <nl> swoole_redis_coro_close ( getThis ( ) ) ; <nl> } <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( redis - > context - > err ) ) ; <nl> RETURN_FALSE ; <nl> } <nl> } <nl> static PHP_METHOD ( swoole_redis_coro , subscribe ) <nl> } <nl> else <nl> { <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( redis - > context - > err ) ) ; <nl> if ( redis - > context - > err = = REDIS_ERR_EOF ) <nl> { <nl> swoole_redis_coro_close ( getThis ( ) ) ; <nl> } <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , getThis ( ) , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( redis - > context - > err ) ) ; <nl> RETURN_FALSE ; <nl> } <nl> } <nl> static void swoole_redis_coro_parse_result ( swRedisClient * redis , zval * return_va <nl> size_t str_len = strlen ( reply - > str ) ; <nl> memcpy ( redis - > context - > errstr , reply - > str , MIN ( str_len , sizeof ( redis - > context - > errstr ) - 1 ) ) ; <nl> } <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( redis - > context - > err ) ) ; <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errMsg " ) , redis - > context - > errstr ) ; <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( redis - > context - > err ) ) ; <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errMsg " ) , redis - > context - > errstr ) ; <nl> break ; <nl> <nl> case REDIS_REPLY_STATUS : <nl> static void swoole_redis_coro_parse_result ( swRedisClient * redis , zval * return_va <nl> } <nl> else <nl> { <nl> - zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( redis - > context - > err ) ) ; <nl> - zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errMsg " ) , redis - > context - > errstr ) ; <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errCode " ) , SW_REDIS_CONVERT_ERR ( redis - > context - > err ) ) ; <nl> + zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > zobject , ZEND_STRL ( " errMsg " ) , redis - > context - > errstr ) ; <nl> } <nl> break ; <nl> <nl>
Make some changes for redis mode to let it ' s connection behavior as same as phpredis , add setOption method ( support SWOOLE_REDIS_OPT_SERIALIZER , SWOOLE_REDIS_OPT_READ_TIMEOUT ) .
swoole/swoole-src
366a2253f7f5288187b48b8908b435736ae14e4e
2018-12-06T08:50:17Z
mmm a / plugins / http_plugin / http_plugin . cpp <nl> ppp b / plugins / http_plugin / http_plugin . cpp <nl> namespace eosio { <nl> } <nl> } <nl> <nl> - # define CALL ( api_name , call_name , http_response_code ) \ <nl> - { std : : string ( " / v1 / " # api_name " / " # call_name ) , \ <nl> - [ & ] ( string , string body , url_response_callback cb ) mutable { \ <nl> - try { \ <nl> - if ( body . empty ( ) ) body = " { } " ; \ <nl> - auto result = ( * this ) . call_name ( ) ; \ <nl> - cb ( http_response_code , fc : : json : : to_string ( result ) ) ; \ <nl> - } catch ( . . . ) { \ <nl> - http_plugin : : handle_exception ( # api_name , # call_name , body , cb ) ; \ <nl> - } \ <nl> - } } <nl> - <nl> - add_api ( { <nl> - CALL ( node , get_supported_apis , 200 ) <nl> - } ) ; <nl> + add_api ( { { <nl> + std : : string ( " / v1 / node / get_supported_apis " ) , <nl> + [ & ] ( string , string body , url_response_callback cb ) mutable { <nl> + try { <nl> + if ( body . empty ( ) ) body = " { } " ; <nl> + auto result = ( * this ) . get_supported_apis ( ) ; <nl> + cb ( 200 , fc : : json : : to_string ( result ) ) ; <nl> + } catch ( . . . ) { <nl> + handle_exception ( " node " , " get_supported_apis " , body , cb ) ; <nl> + } <nl> + } <nl> + } } ) ; <nl> } <nl> <nl> void http_plugin : : plugin_shutdown ( ) { <nl>
Remove redundant macro
EOSIO/eos
289c0d65d21bf5b11b865ec1dd30cf460805f64d
2019-01-12T12:41:46Z
mmm a / xbmc / rendering / gl / RenderSystemGL . cpp <nl> ppp b / xbmc / rendering / gl / RenderSystemGL . cpp <nl> bool CRenderSystemGL : : ResetRenderSystem ( int width , int height , bool fullScreen , <nl> glEnable ( GL_SCISSOR_TEST ) ; <nl> <nl> glMatrixProject . Clear ( ) ; <nl> - glMatrixModview - > LoadIdentity ( ) ; <nl> + glMatrixProject - > LoadIdentity ( ) ; <nl> glMatrixProject - > Ortho ( 0 . 0f , width - 1 , height - 1 , 0 . 0f , - 1 . 0f , 1 . 0f ) ; <nl> glMatrixProject . Load ( ) ; <nl> <nl> mmm a / xbmc / rendering / gles / RenderSystemGLES . cpp <nl> ppp b / xbmc / rendering / gles / RenderSystemGLES . cpp <nl> bool CRenderSystemGLES : : ResetRenderSystem ( int width , int height , bool fullScreen <nl> glEnable ( GL_SCISSOR_TEST ) ; <nl> <nl> glMatrixProject . Clear ( ) ; <nl> - glMatrixModview - > LoadIdentity ( ) ; <nl> + glMatrixProject - > LoadIdentity ( ) ; <nl> glMatrixProject - > Ortho ( 0 . 0f , width - 1 , height - 1 , 0 . 0f , - 1 . 0f , 1 . 0f ) ; <nl> glMatrixProject . Load ( ) ; <nl> <nl>
RenderSystem : Load correct identity
xbmc/xbmc
f90d6b014de5aeb82b9073198e3f328671044759
2016-05-13T18:57:43Z
mmm a / _WAF_ / specs / gamesdk . json <nl> ppp b / _WAF_ / specs / gamesdk . json <nl> <nl> <nl> " CryGameSDK " <nl> ] , <nl> - <nl> - " force_shared_monolithic_build_modules " : <nl> - [ <nl> - " CrySchematycCore " , <nl> - " CrySchematycSTDEnv " <nl> - ] , <nl> - <nl> + <nl> " win_force_shared_monolithic_build_modules " : <nl> [ <nl> " CryAudioImplSDLMixer " , <nl> mmm a / _WAF_ / specs / gamesdk_server . json <nl> ppp b / _WAF_ / specs / gamesdk_server . json <nl> <nl> " CryGameSDK " <nl> ] , <nl> <nl> - " force_shared_monolithic_build_modules " : <nl> - [ <nl> - " CrySchematycCore " , <nl> - " CrySchematycSTDEnv " <nl> - ] , <nl> - <nl> " defines " : [ " DEDICATED_SERVER " ] , <nl> <nl> " win_modules " : [ " DedicatedLauncher " , " CryMonoBridge " , " CryUserAnalytics " ] , <nl> mmm a / _WAF_ / specs / gamezero . json <nl> ppp b / _WAF_ / specs / gamezero . json <nl> <nl> <nl> " CryGameZero " <nl> ] , <nl> - <nl> - " force_shared_monolithic_build_modules " : <nl> - [ <nl> - " CrySchematycCore " , <nl> - " CrySchematycSTDEnv " <nl> - ] , <nl> - <nl> + <nl> " win_force_shared_monolithic_build_modules " : <nl> [ <nl> " CryAudioImplSDLMixer " , <nl> mmm a / _WAF_ / specs / gamezero_server . json <nl> ppp b / _WAF_ / specs / gamezero_server . json <nl> <nl> <nl> " CryGameZero " <nl> ] , <nl> - <nl> - " force_shared_monolithic_build_modules " : <nl> - [ <nl> - " CrySchematycCore " , <nl> - " CrySchematycSTDEnv " <nl> - ] , <nl> <nl> " defines " : [ " DEDICATED_SERVER " ] , <nl> <nl>
! XB ( WAF ) Fix monolithic builds ( Approved by achim )
CRYTEK/CRYENGINE
f2c6d7d701207d07ab3bd37a26f758a7a2cc2210
2016-11-28T14:49:28Z
mmm a / src / cpp / server / server_cc . cc <nl> ppp b / src / cpp / server / server_cc . cc <nl> namespace { <nl> / / max - threads set ) to the server builder . <nl> # define DEFAULT_MAX_SYNC_SERVER_THREADS INT_MAX <nl> <nl> + / / How many callback requests of each method should we pre - register at start <nl> + # define DEFAULT_CALLBACK_REQS_PER_METHOD 32 <nl> + <nl> class DefaultGlobalCallbacks final : public Server : : GlobalCallbacks { <nl> public : <nl> ~ DefaultGlobalCallbacks ( ) override { } <nl> bool Server : : RegisterService ( const grpc : : string * host , Service * service ) { <nl> ( * it ) - > AddSyncMethod ( method , method_registration_tag ) ; <nl> } <nl> } else { <nl> - / / a callback method <nl> - auto * req = new CallbackRequest ( this , method , method_registration_tag ) ; <nl> - callback_reqs_ . emplace_back ( req ) ; <nl> + / / a callback method . Register at least some callback requests <nl> + / / TODO ( vjpai ) : Register these dynamically based on need <nl> + for ( int i = 0 ; i < DEFAULT_CALLBACK_REQS_PER_METHOD ; i + + ) { <nl> + auto * req = new CallbackRequest ( this , method , method_registration_tag ) ; <nl> + callback_reqs_ . emplace_back ( req ) ; <nl> + } <nl> / / Enqueue it so that it will be Request ' ed later once <nl> / / all request matchers are created at core server startup <nl> } <nl>
Pre - request 32 callbacks of each method
grpc/grpc
926b2941abd8363c656330a4923fca33bae4789c
2018-11-08T20:11:57Z
mmm a / libs / libdaemon / src / BaseDaemon . cpp <nl> ppp b / libs / libdaemon / src / BaseDaemon . cpp <nl> size_t backtraceLibUnwind ( void * * out_frames , size_t max_frames , ucontext_t & co <nl> unw_word_t ip ; <nl> unw_get_reg ( & cursor , UNW_REG_IP , & ip ) ; <nl> out_frames [ i ] = reinterpret_cast < void * > ( ip ) ; <nl> + <nl> + / / / NOTE This triggers " AddressSanitizer : stack - buffer - overflow " . Looks like false positive . <nl> + / / / It ' s Ok , because we use this method if the program is crashed nevertheless . <nl> if ( ! unw_step ( & cursor ) ) <nl> break ; <nl> } <nl>
Added comment [ # CLICKHOUSE - 2 ] .
ClickHouse/ClickHouse
f36af6187b3d57a6ce853774ce967db467dbf728
2018-01-13T01:40:43Z
similarity index 87 % <nl> rename from Source / Readers / CNTKTextFormatReader / TextReader . cpp <nl> rename to Source / Readers / CNTKTextFormatReader / CNTKTextFormatReader . cpp <nl> mmm a / Source / Readers / CNTKTextFormatReader / TextReader . cpp <nl> ppp b / Source / Readers / CNTKTextFormatReader / CNTKTextFormatReader . cpp <nl> <nl> / / <nl> <nl> # include " stdafx . h " <nl> - # include " TextReader . h " <nl> + # include " CNTKTextFormatReader . h " <nl> # include " Config . h " <nl> # include " TextConfigHelper . h " <nl> # include " BlockRandomizer . h " <nl> <nl> <nl> namespace Microsoft { namespace MSR { namespace CNTK { <nl> <nl> - TextReader : : TextReader ( MemoryProviderPtr provider , <nl> + CNTKTextFormatReader : : CNTKTextFormatReader ( MemoryProviderPtr provider , <nl> const ConfigParameters & config ) <nl> : m_provider ( provider ) <nl> { <nl> TextReader : : TextReader ( MemoryProviderPtr provider , <nl> m_transformer = randomizer ; <nl> } <nl> <nl> - std : : vector < StreamDescriptionPtr > TextReader : : GetStreamDescriptions ( ) <nl> + std : : vector < StreamDescriptionPtr > CNTKTextFormatReader : : GetStreamDescriptions ( ) <nl> { <nl> return m_deserializer - > GetStreamDescriptions ( ) ; <nl> } <nl> <nl> - void TextReader : : StartEpoch ( const EpochConfiguration & config ) <nl> + void CNTKTextFormatReader : : StartEpoch ( const EpochConfiguration & config ) <nl> { <nl> if ( config . m_totalEpochSizeInSamples < = 0 ) <nl> { <nl> void TextReader : : StartEpoch ( const EpochConfiguration & config ) <nl> GetStreamDescriptions ( ) ) ; <nl> } <nl> <nl> - Minibatch TextReader : : ReadMinibatch ( ) <nl> + Minibatch CNTKTextFormatReader : : ReadMinibatch ( ) <nl> { <nl> assert ( m_packer ! = nullptr ) ; <nl> return m_packer - > ReadMinibatch ( ) ; <nl> similarity index 92 % <nl> rename from Source / Readers / CNTKTextFormatReader / TextReader . h <nl> rename to Source / Readers / CNTKTextFormatReader / CNTKTextFormatReader . h <nl> mmm a / Source / Readers / CNTKTextFormatReader / TextReader . h <nl> ppp b / Source / Readers / CNTKTextFormatReader / CNTKTextFormatReader . h <nl> namespace Microsoft { namespace MSR { namespace CNTK { <nl> / / Implementation of the text reader . <nl> / / Effectively the class represents a factory for connecting the packer , <nl> / / transformers and the deserializer together . <nl> - class TextReader : public Reader <nl> + class CNTKTextFormatReader : public Reader <nl> { <nl> public : <nl> - TextReader ( MemoryProviderPtr provider , <nl> + CNTKTextFormatReader ( MemoryProviderPtr provider , <nl> const ConfigParameters & parameters ) ; <nl> <nl> / / Description of streams that this reader provides . <nl> mmm a / Source / Readers / CNTKTextFormatReader / CNTKTextFormatReader . vcxproj <nl> ppp b / Source / Readers / CNTKTextFormatReader / CNTKTextFormatReader . vcxproj <nl> <nl> < SDLCheck > true < / SDLCheck > <nl> < TreatWarningAsError > true < / TreatWarningAsError > <nl> < OpenMPSupport > true < / OpenMPSupport > <nl> + < AdditionalIncludeDirectories > . . / ReaderLib < / AdditionalIncludeDirectories > <nl> < / ClCompile > <nl> < Link > <nl> < SubSystem > Windows < / SubSystem > <nl> <nl> < ClCompile > <nl> < Optimization > Disabled < / Optimization > <nl> < PreprocessorDefinitions > _DEBUG ; % ( PreprocessorDefinitions ) < / PreprocessorDefinitions > <nl> - < AdditionalIncludeDirectories > . . / ReaderLib < / AdditionalIncludeDirectories > <nl> < / ClCompile > <nl> < / ItemDefinitionGroup > <nl> < ItemDefinitionGroup Condition = " $ ( ReleaseBuild ) " > <nl> <nl> < IntrinsicFunctions > true < / IntrinsicFunctions > <nl> < PreprocessorDefinitions > NDEBUG ; % ( PreprocessorDefinitions ) < / PreprocessorDefinitions > <nl> < AdditionalOptions > / d2Zi + % ( AdditionalOptions ) < / AdditionalOptions > <nl> - < AdditionalIncludeDirectories > . . / ReaderLib < / AdditionalIncludeDirectories > <nl> < / ClCompile > <nl> < Link > <nl> < EnableCOMDATFolding > true < / EnableCOMDATFolding > <nl> <nl> < ClInclude Include = " TextConfigHelper . h " / > <nl> < ClInclude Include = " TextParser . h " / > <nl> < ClInclude Include = " Descriptors . h " / > <nl> - < ClInclude Include = " TextReader . h " / > <nl> + < ClInclude Include = " CNTKTextFormatReader . h " / > <nl> < ClInclude Include = " stdafx . h " / > <nl> < ClInclude Include = " targetver . h " / > <nl> < / ItemGroup > <nl> <nl> < ClCompile Include = " TextParser . cpp " / > <nl> < ClCompile Include = " dllmain . cpp " / > <nl> < ClCompile Include = " Exports . cpp " / > <nl> - < ClCompile Include = " TextReader . cpp " / > <nl> + < ClCompile Include = " CNTKTextFormatReader . cpp " / > <nl> < ClCompile Include = " stdafx . cpp " > <nl> < PrecompiledHeader > Create < / PrecompiledHeader > <nl> < / ClCompile > <nl> mmm a / Source / Readers / CNTKTextFormatReader / CNTKTextFormatReader . vcxproj . filters <nl> ppp b / Source / Readers / CNTKTextFormatReader / CNTKTextFormatReader . vcxproj . filters <nl> <nl> < Filter > Common < / Filter > <nl> < / ClCompile > <nl> < ClCompile Include = " dllmain . cpp " / > <nl> - < ClCompile Include = " TextReader . cpp " / > <nl> < ClCompile Include = " TextConfigHelper . cpp " / > <nl> < ClCompile Include = " . . \ . . \ Common \ Config . cpp " > <nl> < Filter > Common < / Filter > <nl> < / ClCompile > <nl> < ClCompile Include = " Indexer . cpp " / > <nl> < ClCompile Include = " TextParser . cpp " / > <nl> + < ClCompile Include = " CNTKTextFormatReader . cpp " / > <nl> < / ItemGroup > <nl> < ItemGroup > <nl> < ClInclude Include = " stdafx . h " / > <nl> <nl> < ClInclude Include = " . . \ . . \ Common \ Include \ fileutil . h " > <nl> < Filter > Common \ Include < / Filter > <nl> < / ClInclude > <nl> - < ClInclude Include = " TextReader . h " / > <nl> < ClInclude Include = " TextConfigHelper . h " / > <nl> < ClInclude Include = " Descriptors . h " / > <nl> < ClInclude Include = " Indexer . h " / > <nl> < ClInclude Include = " TextReaderConstants . h " / > <nl> < ClInclude Include = " TextParser . h " / > <nl> + < ClInclude Include = " CNTKTextFormatReader . h " / > <nl> < / ItemGroup > <nl> < ItemGroup > <nl> < Filter Include = " Common " > <nl> mmm a / Source / Readers / CNTKTextFormatReader / Descriptors . h <nl> ppp b / Source / Readers / CNTKTextFormatReader / Descriptors . h <nl> namespace Microsoft { namespace MSR { namespace CNTK { <nl> m_numberOfSamples = 0 ; <nl> m_chunkId = 0 ; <nl> m_isValid = false ; <nl> - m_fileOffset = 0 ; <nl> + m_fileOffsetBytes = 0 ; <nl> m_byteSize = 0 ; <nl> } <nl> / / size_t m_numberOfSamples - - number of samples in the sequence ( largest count among all inputs ) <nl> / / in case of text data this value = = number of rows this sequence spans over . <nl> - int64_t m_fileOffset ; / / sequence offset in the input file ( in bytes ) <nl> - int64_t m_byteSize ; / / size in bytes <nl> + int64_t m_fileOffsetBytes ; / / sequence offset in the input file ( in bytes ) <nl> + size_t m_byteSize ; / / size in bytes <nl> } ; <nl> <nl> / / Chunk metadata <nl> struct ChunkDescriptor <nl> { <nl> size_t m_id ; <nl> - int64_t m_byteSize ; / / size in bytes <nl> + size_t m_byteSize ; / / size in bytes <nl> size_t m_numSequences ; / / number of sequences in this chunk <nl> TimelineOffset m_timelineOffset ; / / offset into the timeline <nl> } ; <nl> mmm a / Source / Readers / CNTKTextFormatReader / Exports . cpp <nl> ppp b / Source / Readers / CNTKTextFormatReader / Exports . cpp <nl> <nl> # define DATAREADER_EXPORTS <nl> # include " DataReader . h " <nl> # include " ReaderShim . h " <nl> - # include " TextReader . h " <nl> + # include " CNTKTextFormatReader . h " <nl> # include " HeapMemoryProvider . h " <nl> # include " CudaMemoryProvider . h " <nl> <nl> namespace Microsoft { namespace MSR { namespace CNTK { <nl> <nl> auto factory = [ ] ( const ConfigParameters & parameters ) - > ReaderPtr <nl> { <nl> - return std : : make_shared < TextReader > ( std : : make_shared < HeapMemoryProvider > ( ) , parameters ) ; <nl> + return std : : make_shared < CNTKTextFormatReader > ( std : : make_shared < HeapMemoryProvider > ( ) , parameters ) ; <nl> } ; <nl> <nl> extern " C " DATAREADER_API void GetReaderF ( IDataReader * * preader ) <nl> mmm a / Source / Readers / CNTKTextFormatReader / Indexer . cpp <nl> ppp b / Source / Readers / CNTKTextFormatReader / Indexer . cpp <nl> using std : : string ; <nl> <nl> namespace Microsoft { namespace MSR { namespace CNTK { <nl> <nl> - Indexer : : Indexer ( FILE * file , bool skipSequenceIds , int64_t chunkSize ) : m_maxChunkSize ( chunkSize ) { <nl> - if ( ! file ) { <nl> + Indexer : : Indexer ( FILE * file , bool skipSequenceIds , size_t chunkSize ) <nl> + : m_maxChunkSize ( chunkSize ) , m_buffer ( new char [ BUFFER_SIZE + 1 ] ) <nl> + { <nl> + if ( file = = nullptr ) <nl> + { <nl> RuntimeError ( " Input file not open for reading " ) ; <nl> } <nl> m_file = file ; <nl> - m_bufferStart = new char [ BUFFER_SIZE + 1 ] ; <nl> + m_bufferStart = m_buffer . get ( ) ; <nl> m_fileOffsetStart = 0 ; <nl> m_fileOffsetEnd = 0 ; <nl> m_done = false ; <nl> Indexer : : Indexer ( FILE * file , bool skipSequenceIds , int64_t chunkSize ) : m_maxChu <nl> m_chunks . push_back ( { } ) ; <nl> } <nl> <nl> - Indexer : : ~ Indexer ( ) { <nl> - delete [ ] m_bufferStart ; <nl> + int64_t Indexer : : GetFileOffset ( ) <nl> + { <nl> + return m_fileOffsetStart + ( m_pos - m_bufferStart ) ; <nl> } <nl> <nl> - void Indexer : : Fill ( ) { <nl> - if ( ! m_done ) { <nl> + void Indexer : : Fill ( ) <nl> + { <nl> + if ( ! m_done ) <nl> + { <nl> size_t bytesRead = fread ( m_bufferStart , 1 , BUFFER_SIZE , m_file ) ; <nl> if ( bytesRead = = ( size_t ) - 1 ) <nl> RuntimeError ( " Could not read from the input file . " ) ; <nl> - if ( ! bytesRead ) { <nl> + if ( bytesRead = = 0 ) <nl> + { <nl> m_done = true ; <nl> } <nl> - else { <nl> + else <nl> + { <nl> m_fileOffsetStart = m_fileOffsetEnd ; <nl> m_fileOffsetEnd + = bytesRead ; <nl> m_pos = m_bufferStart ; <nl> void Indexer : : Fill ( ) { <nl> } <nl> } <nl> <nl> - void Indexer : : UpdateTimeline ( SequenceDescriptor & sd ) { <nl> + void Indexer : : UpdateTimeline ( SequenceDescriptor & sd ) <nl> + { <nl> + assert ( ! m_chunks . empty ( ) ) ; <nl> ChunkDescriptor * chunk = & m_chunks . back ( ) ; <nl> TimelineOffset timelineOffset = m_timeline . size ( ) ; <nl> - if ( chunk - > m_byteSize > 0 & & ( chunk - > m_byteSize + sd . m_byteSize ) > m_maxChunkSize ) { <nl> + if ( chunk - > m_byteSize > 0 & & ( chunk - > m_byteSize + sd . m_byteSize ) > m_maxChunkSize ) <nl> + { <nl> m_chunks . push_back ( { } ) ; <nl> chunk = & m_chunks . back ( ) ; <nl> chunk - > m_id = m_chunks . size ( ) - 1 ; <nl> void Indexer : : UpdateTimeline ( SequenceDescriptor & sd ) { <nl> m_timeline . push_back ( sd ) ; <nl> } <nl> <nl> - std : : shared_ptr < Index > Indexer : : BuildFromLines ( ) { <nl> + std : : shared_ptr < Index > Indexer : : BuildFromLines ( ) <nl> + { <nl> m_skipSequenceIds = true ; <nl> size_t lines = 0 ; <nl> int64_t offset = m_fileOffsetStart ; <nl> while ( ! m_done ) <nl> { <nl> m_pos = ( char * ) memchr ( m_pos , ROW_DELIMITER , m_bufferEnd - m_pos ) ; <nl> - if ( m_pos ) { <nl> + if ( m_pos ) <nl> + { <nl> SequenceDescriptor sd = { } ; <nl> sd . m_id = lines ; <nl> sd . m_numberOfSamples = 1 ; <nl> sd . m_isValid = true ; <nl> - sd . m_fileOffset = offset ; <nl> + sd . m_fileOffsetBytes = offset ; <nl> sd . m_byteSize = ( m_fileOffsetEnd - ( m_bufferEnd - m_pos ) ) - offset + 1 ; <nl> offset + = sd . m_byteSize ; <nl> UpdateTimeline ( sd ) ; <nl> + + m_pos ; <nl> + + lines ; <nl> } <nl> - else { <nl> + else <nl> + { <nl> Fill ( ) ; <nl> } <nl> } <nl> std : : shared_ptr < Index > Indexer : : BuildFromLines ( ) { <nl> } <nl> <nl> <nl> - std : : shared_ptr < Index > Indexer : : Build ( ) { <nl> + std : : shared_ptr < Index > Indexer : : Build ( ) <nl> + { <nl> Fill ( ) ; / / read the first block of data <nl> - if ( m_done ) { <nl> + if ( m_done ) <nl> + { <nl> RuntimeError ( " Input file is empty " ) ; <nl> } <nl> <nl> - if ( ( m_bufferEnd - m_bufferStart > 3 ) & & <nl> + if ( ( m_bufferEnd - m_bufferStart > 3 ) & & <nl> ( m_bufferStart [ 0 ] = = ' \ xEF ' & & m_bufferStart [ 1 ] = = ' \ xBB ' & & m_bufferStart [ 2 ] = = ' \ xBF ' ) ) <nl> { <nl> / / input file contains UTF - 8 BOM value , skip it . <nl> std : : shared_ptr < Index > Indexer : : Build ( ) { <nl> } <nl> <nl> / / check the first byte and decide what to do next <nl> - if ( m_skipSequenceIds | | m_bufferStart [ 0 ] = = NAME_PREFIX ) { <nl> + if ( m_skipSequenceIds | | m_bufferStart [ 0 ] = = NAME_PREFIX ) <nl> + { <nl> / / skip sequence id parsing , treat lines as individual sequences <nl> return BuildFromLines ( ) ; <nl> } <nl> std : : shared_ptr < Index > Indexer : : Build ( ) { <nl> size_t id = 0 ; <nl> int64_t offset = m_fileOffsetStart + ( m_pos - m_bufferStart ) ; <nl> / / read the very first sequence id <nl> - if ( ! GetNextSequenceId ( id ) ) { <nl> - RuntimeError ( " Expected a sequence id at the offset % " PRIi64 " , none was found . " , <nl> - offset ) ; <nl> + if ( ! GetNextSequenceId ( id ) ) <nl> + { <nl> + RuntimeError ( " Expected a sequence id at the offset % " PRIi64 " , none was found . " , offset ) ; <nl> } <nl> <nl> - SequenceDescriptor sd = SequenceDescriptor ( ) ; <nl> + SequenceDescriptor sd = { } ; <nl> sd . m_id = id ; <nl> - sd . m_fileOffset = offset ; <nl> + sd . m_fileOffsetBytes = offset ; <nl> sd . m_isValid = true ; <nl> <nl> - while ( ! m_done ) { <nl> + while ( ! m_done ) <nl> + { <nl> SkipLine ( ) ; / / ignore whatever is left on this line . <nl> offset = m_fileOffsetStart + ( m_pos - m_bufferStart ) ; / / a new line starts at this offset ; <nl> - sd . m_numberOfSamples + + ; <nl> + sd . m_numberOfSamples + + ; <nl> <nl> - if ( ! m_done & & GetNextSequenceId ( id ) & & id ! = sd . m_id ) { <nl> + if ( ! m_done & & GetNextSequenceId ( id ) & & id ! = sd . m_id ) <nl> + { <nl> / / found a new sequence , which starts at the [ offset ] bytes into the file <nl> - sd . m_byteSize = offset - sd . m_fileOffset ; <nl> + sd . m_byteSize = offset - sd . m_fileOffsetBytes ; <nl> UpdateTimeline ( sd ) ; <nl> - sd = SequenceDescriptor ( ) ; <nl> + sd = { } ; <nl> sd . m_id = id ; <nl> - sd . m_fileOffset = offset ; <nl> + sd . m_fileOffsetBytes = offset ; <nl> sd . m_isValid = true ; <nl> } <nl> } <nl> <nl> / / calculate the byte size for the last sequence <nl> - sd . m_byteSize = m_fileOffsetEnd - sd . m_fileOffset ; <nl> + sd . m_byteSize = m_fileOffsetEnd - sd . m_fileOffsetBytes ; <nl> UpdateTimeline ( sd ) ; <nl> <nl> return make_shared < Index > ( <nl> std : : shared_ptr < Index > Indexer : : Build ( ) { <nl> } <nl> <nl> <nl> - void Indexer : : SkipLine ( ) { <nl> + void Indexer : : SkipLine ( ) <nl> + { <nl> while ( ! m_done ) <nl> { <nl> m_pos = ( char * ) memchr ( m_pos , ROW_DELIMITER , m_bufferEnd - m_pos ) ; <nl> - if ( m_pos ) { <nl> + if ( m_pos ) <nl> + { <nl> / / found a new - line character <nl> - if ( + + m_pos = = m_bufferEnd ) { <nl> + if ( + + m_pos = = m_bufferEnd ) <nl> + { <nl> Fill ( ) ; <nl> } <nl> return ; <nl> void Indexer : : SkipLine ( ) { <nl> } <nl> } <nl> <nl> - bool Indexer : : GetNextSequenceId ( size_t & id ) { <nl> + bool Indexer : : GetNextSequenceId ( size_t & id ) <nl> + { <nl> bool found = false ; <nl> id = 0 ; <nl> while ( ! m_done ) <nl> { <nl> - while ( m_pos ! = m_bufferEnd ) <nl> + while ( m_pos ! = m_bufferEnd ) <nl> { <nl> char c = * m_pos ; <nl> / / a well - formed sequence id must end in either a column delimiter <nl> / / or a name prefix <nl> - if ( c = = COLUMN_DELIMITER | | c = = NAME_PREFIX ) <nl> + if ( c = = COLUMN_DELIMITER | | c = = NAME_PREFIX ) <nl> { <nl> return found ; <nl> } <nl> <nl> - if ( c < ' 0 ' | | c > ' 9 ' ) <nl> + if ( c < ' 0 ' | | c > ' 9 ' ) <nl> { <nl> / / TODO : ignore malformed sequences <nl> RuntimeError ( " Unexpected character ( ' % c ' ) " <nl> mmm a / Source / Readers / CNTKTextFormatReader / Indexer . h <nl> ppp b / Source / Readers / CNTKTextFormatReader / Indexer . h <nl> class Indexer <nl> int64_t m_fileOffsetStart ; <nl> int64_t m_fileOffsetEnd ; <nl> <nl> + unique_ptr < char [ ] > m_buffer ; <nl> char * m_bufferStart = nullptr ; <nl> char * m_bufferEnd = nullptr ; <nl> char * m_pos = nullptr ; / / buffer index <nl> class Indexer <nl> bool m_skipSequenceIds ; / / true , when input contains one sequence per line <nl> / / and sequence id column can be skipped . <nl> <nl> - const int64_t m_maxChunkSize ; / / maximum permited chunk size ; <nl> + const size_t m_maxChunkSize ; / / maximum permited chunk size ; <nl> <nl> std : : vector < SequenceDescriptor > m_timeline ; <nl> std : : vector < ChunkDescriptor > m_chunks ; <nl> class Indexer <nl> std : : shared_ptr < Index > BuildFromLines ( ) ; <nl> <nl> <nl> - int64_t GetFileOffset ( ) { return m_fileOffsetStart + ( m_pos - m_bufferStart ) ; } <nl> + int64_t GetFileOffset ( ) ; <nl> <nl> - Indexer ( const Indexer & ) = delete ; <nl> - Indexer & operator = ( const Indexer & ) = delete ; <nl> + DISABLE_COPY_AND_MOVE ( Indexer ) ; <nl> <nl> public : <nl> - Indexer ( FILE * file , bool skipSequenceIds , int64_t chunkSize = 32 * 1024 * 1024 ) ; <nl> - <nl> - ~ Indexer ( ) ; <nl> + Indexer ( FILE * file , bool skipSequenceIds , size_t chunkSize = 32 * 1024 * 1024 ) ; <nl> <nl> / / Reads the input file building an index of sequence metadata . <nl> std : : shared_ptr < Index > Build ( ) ; <nl> mmm a / Source / Readers / CNTKTextFormatReader / TextConfigHelper . cpp <nl> ppp b / Source / Readers / CNTKTextFormatReader / TextConfigHelper . cpp <nl> using std : : map ; <nl> <nl> namespace Microsoft { namespace MSR { namespace CNTK { <nl> <nl> - TextConfigHelper : : TextConfigHelper ( const ConfigParameters & config ) <nl> + TextConfigHelper : : TextConfigHelper ( const ConfigParameters & config ) <nl> + { <nl> + if ( ! config . ExistsCurrent ( L " input " ) ) <nl> { <nl> + RuntimeError ( " CNTKTextFormatReader configuration does not contain input section " ) ; <nl> + } <nl> + <nl> + const ConfigParameters & input = config ( L " input " ) ; <nl> + <nl> + if ( input . empty ( ) ) <nl> + { <nl> + RuntimeError ( " CNTKTextFormatReader configuration contains an empty input section " ) ; <nl> + } <nl> <nl> - if ( ! config . ExistsCurrent ( L " input " ) ) <nl> + m_elementType = ElementType : : tfloat ; <nl> + string precision = config . Find ( " precision " , " float " ) ; <nl> + if ( AreEqualIgnoreCase ( precision , " double " ) ) <nl> + { <nl> + m_elementType = ElementType : : tdouble ; <nl> + } <nl> + else if ( ! AreEqualIgnoreCase ( precision , " float " ) ) <nl> + { <nl> + RuntimeError ( " Not supported precision ' % s ' . Expected ' double ' or ' float ' . " , precision . c_str ( ) ) ; <nl> + } <nl> + <nl> + StreamId id = 0 ; <nl> + map < string , wstring > aliasToInputMap ; <nl> + for ( const pair < string , ConfigParameters > & section : input ) <nl> + { <nl> + ConfigParameters input = section . second ; <nl> + const wstring & name = msra : : strfun : : utf16 ( section . first ) ; <nl> + <nl> + if ( ! input . ExistsCurrent ( L " dim " ) | | ! input . ExistsCurrent ( L " format " ) ) <nl> { <nl> - RuntimeError ( " CNTKTextFormatReader configuration does not contain input section " ) ; <nl> + RuntimeError ( " Input section for input ' % ls ' does not specify all the required parameters , " <nl> + " \ " dim \ " and \ " format \ " . " , name . c_str ( ) ) ; <nl> } <nl> <nl> - const ConfigParameters & input = config ( L " input " ) ; <nl> + StreamDescriptor stream ; <nl> + stream . m_id = id + + ; <nl> + stream . m_name = name ; <nl> + stream . m_sampleDimension = input ( L " dim " ) ; <nl> + string type = input ( L " format " ) ; <nl> <nl> - if ( input . empty ( ) ) <nl> + if ( AreEqualIgnoreCase ( type , " dense " ) ) <nl> { <nl> - RuntimeError ( " CNTKTextFormatReader configuration contains an empty input section " ) ; <nl> + stream . m_storageType = StorageType : : dense ; <nl> } <nl> - <nl> - m_elementType = ElementType : : tfloat ; <nl> - string precision = config . Find ( " precision " , " float " ) ; <nl> - if ( AreEqualIgnoreCase ( precision , " double " ) ) <nl> + else if ( AreEqualIgnoreCase ( type , " sparse " ) ) <nl> { <nl> - m_elementType = ElementType : : tdouble ; <nl> + stream . m_storageType = StorageType : : sparse_csc ; <nl> } <nl> - else if ( ! AreEqualIgnoreCase ( precision , " float " ) ) <nl> + else <nl> { <nl> - RuntimeError ( " Not supported precision ' % s ' . Expected ' double ' or ' float ' . " , precision . c_str ( ) ) ; <nl> + RuntimeError ( " ' format ' parameter must be set either to ' dense ' or ' sparse ' " ) ; <nl> } <nl> <nl> - StreamId id = 0 ; <nl> - map < string , wstring > aliasToInputMap ; <nl> - for ( const pair < string , ConfigParameters > & section : input ) <nl> + / / alias is optional <nl> + if ( input . ExistsCurrent ( L " alias " ) ) <nl> { <nl> - ConfigParameters input = section . second ; <nl> - const wstring & name = msra : : strfun : : utf16 ( section . first ) ; <nl> - <nl> - if ( ! input . ExistsCurrent ( L " dim " ) | | ! input . ExistsCurrent ( L " format " ) ) { <nl> - RuntimeError ( " Input section for input ' % ls ' does not specify all the required parameters , " <nl> - " \ " dim \ " and \ " format \ " . " , name . c_str ( ) ) ; <nl> - } <nl> - <nl> - StreamDescriptor stream ; <nl> - stream . m_id = id + + ; <nl> - stream . m_name = name ; <nl> - stream . m_sampleDimension = input ( L " dim " ) ; <nl> - string type = input ( L " format " ) ; <nl> - <nl> - if ( AreEqualIgnoreCase ( type , " dense " ) ) <nl> - { <nl> - stream . m_storageType = StorageType : : dense ; <nl> - } <nl> - else if ( AreEqualIgnoreCase ( type , " sparse " ) ) <nl> - { <nl> - stream . m_storageType = StorageType : : sparse_csc ; <nl> - } <nl> - else <nl> - { <nl> - RuntimeError ( " ' format ' parameter must be set either to ' dense ' or ' sparse ' " ) ; <nl> - } <nl> - <nl> - / / alias is optional <nl> - if ( input . ExistsCurrent ( L " alias " ) ) { <nl> - stream . m_alias = input ( L " alias " ) ; <nl> - if ( stream . m_alias . empty ( ) ) <nl> - { <nl> - RuntimeError ( " Alias value for input ' % ls ' is empty " , name . c_str ( ) ) ; <nl> - } <nl> - } <nl> - else <nl> - { <nl> - stream . m_alias = section . first ; <nl> - } <nl> - <nl> - if ( aliasToInputMap . find ( stream . m_alias ) ! = aliasToInputMap . end ( ) ) <nl> + stream . m_alias = input ( L " alias " ) ; <nl> + if ( stream . m_alias . empty ( ) ) <nl> { <nl> - RuntimeError ( " Alias % s is already mapped to input % ls . " , <nl> - stream . m_alias , aliasToInputMap [ stream . m_alias ] ) ; <nl> + RuntimeError ( " Alias value for input ' % ls ' is empty " , name . c_str ( ) ) ; <nl> } <nl> - else <nl> - { <nl> - aliasToInputMap [ stream . m_alias ] = stream . m_name ; <nl> - } <nl> - <nl> - stream . m_elementType = m_elementType ; <nl> - m_streams . push_back ( stream ) ; <nl> } <nl> - <nl> - <nl> - <nl> - m_filepath = msra : : strfun : : utf16 ( config ( L " file " ) ) ; <nl> - <nl> - string rand = config ( L " randomize " , " auto " ) ; <nl> - <nl> - if ( AreEqualIgnoreCase ( rand , " auto " ) ) <nl> + else <nl> { <nl> - m_randomize = true ; <nl> + stream . m_alias = section . first ; <nl> } <nl> - else if ( AreEqualIgnoreCase ( rand , " none " ) ) <nl> + <nl> + if ( aliasToInputMap . find ( stream . m_alias ) ! = aliasToInputMap . end ( ) ) <nl> { <nl> - m_randomize = false ; <nl> + RuntimeError ( " Alias % s is already mapped to input % ls . " , <nl> + stream . m_alias . c_str ( ) , aliasToInputMap [ stream . m_alias ] . c_str ( ) ) ; <nl> } <nl> else <nl> { <nl> - RuntimeError ( " ' randomize ' parameter must be set to ' auto ' or ' none ' " ) ; <nl> + aliasToInputMap [ stream . m_alias ] = stream . m_name ; <nl> } <nl> <nl> - m_cpuThreadCount = config ( L " numCPUThreads " , 0 ) ; <nl> - m_skipSequenceIds = config ( L " skipSequenceIds " , false ) ; <nl> - m_maxErrors = config ( L " maxErrors " , 0 ) ; <nl> - m_traceLevel = config ( L " traceLevel " , 0 ) ; <nl> - m_chunkSize = config ( L " chunkSize " , 32 * 1024 * 1024 ) ; / / 32 MB by default <nl> - m_chunkCacheSize = config ( L " chunkCacheSize " , 32 ) ; / / GB of memory in total <nl> - } <nl> - <nl> - const wstring & TextConfigHelper : : GetFilePath ( ) const <nl> - { <nl> - return m_filepath ; <nl> - } <nl> - <nl> - int TextConfigHelper : : GetCpuThreadCount ( ) const <nl> - { <nl> - return m_cpuThreadCount ; <nl> + stream . m_elementType = m_elementType ; <nl> + m_streams . push_back ( stream ) ; <nl> } <nl> <nl> - bool TextConfigHelper : : ShouldRandomize ( ) const <nl> - { <nl> - return m_randomize ; <nl> - } <nl> <nl> - const vector < StreamDescriptor > & TextConfigHelper : : GetStreams ( ) const <nl> - { <nl> - return m_streams ; <nl> - } <nl> <nl> - bool TextConfigHelper : : ShouldSkipSequenceIds ( ) const <nl> - { <nl> - return m_skipSequenceIds ; <nl> - } <nl> + m_filepath = msra : : strfun : : utf16 ( config ( L " file " ) ) ; <nl> <nl> - unsigned int TextConfigHelper : : GetMaxAllowedErrors ( ) const <nl> - { <nl> - return m_maxErrors ; <nl> - } <nl> + string rand = config ( L " randomize " , " auto " ) ; <nl> <nl> - unsigned int TextConfigHelper : : GetTraceLevel ( ) const <nl> + if ( AreEqualIgnoreCase ( rand , " auto " ) ) <nl> { <nl> - return m_traceLevel ; <nl> + m_randomize = true ; <nl> } <nl> - <nl> - int64_t TextConfigHelper : : GetChunkSize ( ) const <nl> + else if ( AreEqualIgnoreCase ( rand , " none " ) ) <nl> { <nl> - return m_chunkSize ; <nl> + m_randomize = false ; <nl> } <nl> - <nl> - unsigned int TextConfigHelper : : GetNumChunksToCache ( ) const <nl> + else <nl> { <nl> - return m_chunkCacheSize ; <nl> + RuntimeError ( " ' randomize ' parameter must be set to ' auto ' or ' none ' " ) ; <nl> } <nl> <nl> - ElementType TextConfigHelper : : GetElementType ( ) const <nl> - { <nl> - return m_elementType ; <nl> - } <nl> + m_cpuThreadCount = config ( L " numCPUThreads " , 0 ) ; <nl> + m_skipSequenceIds = config ( L " skipSequenceIds " , false ) ; <nl> + m_maxErrors = config ( L " maxErrors " , 0 ) ; <nl> + m_traceLevel = config ( L " traceLevel " , 0 ) ; <nl> + m_chunkSizeBytes = config ( L " chunkSizeInBytes " , 32 * 1024 * 1024 ) ; / / 32 MB by default <nl> + m_chunkCacheSize = config ( L " numChunksToCache " , 32 ) ; / / 32 * 32 MB = 1 GB of memory in total <nl> + } <nl> + <nl> + const wstring & TextConfigHelper : : GetFilePath ( ) const <nl> + { <nl> + return m_filepath ; <nl> + } <nl> + <nl> + int TextConfigHelper : : GetCpuThreadCount ( ) const <nl> + { <nl> + return m_cpuThreadCount ; <nl> + } <nl> + <nl> + bool TextConfigHelper : : ShouldRandomize ( ) const <nl> + { <nl> + return m_randomize ; <nl> + } <nl> + <nl> + const vector < StreamDescriptor > & TextConfigHelper : : GetStreams ( ) const <nl> + { <nl> + return m_streams ; <nl> + } <nl> + <nl> + bool TextConfigHelper : : ShouldSkipSequenceIds ( ) const <nl> + { <nl> + return m_skipSequenceIds ; <nl> + } <nl> + <nl> + unsigned int TextConfigHelper : : GetMaxAllowedErrors ( ) const <nl> + { <nl> + return m_maxErrors ; <nl> + } <nl> + <nl> + unsigned int TextConfigHelper : : GetTraceLevel ( ) const <nl> + { <nl> + return m_traceLevel ; <nl> + } <nl> + <nl> + size_t TextConfigHelper : : GetChunkSize ( ) const <nl> + { <nl> + return m_chunkSizeBytes ; <nl> + } <nl> + <nl> + unsigned int TextConfigHelper : : GetNumChunksToCache ( ) const <nl> + { <nl> + return m_chunkCacheSize ; <nl> + } <nl> + <nl> + ElementType TextConfigHelper : : GetElementType ( ) const <nl> + { <nl> + return m_elementType ; <nl> + } <nl> } } } <nl> mmm a / Source / Readers / CNTKTextFormatReader / TextConfigHelper . h <nl> ppp b / Source / Readers / CNTKTextFormatReader / TextConfigHelper . h <nl> class TextConfigHelper <nl> <nl> unsigned int GetTraceLevel ( ) const ; <nl> <nl> - int64_t GetChunkSize ( ) const ; <nl> + size_t GetChunkSize ( ) const ; <nl> <nl> unsigned int GetNumChunksToCache ( ) const ; <nl> <nl> void ParseStreamConfig ( const ConfigParameters & config , std : : vector < StreamDescriptor > & streams ) ; <nl> <nl> - private : <nl> - TextConfigHelper ( const TextConfigHelper & ) = delete ; <nl> - TextConfigHelper & operator = ( const TextConfigHelper & ) = delete ; <nl> + DISABLE_COPY_AND_MOVE ( TextConfigHelper ) ; <nl> <nl> + private : <nl> std : : wstring m_filepath ; <nl> std : : vector < StreamDescriptor > m_streams ; <nl> int m_cpuThreadCount ; <nl> class TextConfigHelper <nl> bool m_skipSequenceIds ; <nl> unsigned int m_maxErrors ; <nl> unsigned int m_traceLevel ; <nl> - int64_t m_chunkSize ; / / chunks size in bytes <nl> + size_t m_chunkSizeBytes ; / / chunks size in bytes <nl> unsigned int m_chunkCacheSize ; / / number of chunks to keep in the memory <nl> } ; <nl> <nl> mmm a / Source / Readers / CNTKTextFormatReader / TextParser . cpp <nl> ppp b / Source / Readers / CNTKTextFormatReader / TextParser . cpp <nl> ChunkPtr TextParser < ElemType > : : GetChunk ( size_t chunkId ) <nl> if ( m_chunkCacheSize > 0 & & m_chunkCache . size ( ) = = m_chunkCacheSize ) <nl> { <nl> size_t candidateId = SIZE_MAX ; <nl> - int64_t minNumSequencesLeft = SIZE_MAX ; <nl> + size_t minNumSequencesLeft = SIZE_MAX ; <nl> for ( const auto & it : m_chunkCache ) <nl> { <nl> const auto & chunk = * ( it . second . get ( ) ) ; <nl> size_t numSequencesUsed = 0 ; <nl> # pragma omp atomic <nl> numSequencesUsed + = chunk . m_sequenceRequestCount ; <nl> - int64_t numSequencesLeft = chunk . m_sequenceData . size ( ) - numSequencesUsed ; <nl> + size_t numSequencesLeft = chunk . m_sequenceData . size ( ) - numSequencesUsed ; <nl> if ( numSequencesLeft < minNumSequencesLeft ) <nl> { <nl> minNumSequencesLeft = numSequencesLeft ; <nl> void TextParser < ElemType > : : SetFileOffset ( int64_t offset ) <nl> <nl> template < class ElemType > <nl> Sequence < ElemType > TextParser < ElemType > : : LoadSequence ( bool verifyId , const SequenceDescriptor & sequenceDsc ) { <nl> - auto fileOffset = sequenceDsc . m_fileOffset ; <nl> + auto fileOffset = sequenceDsc . m_fileOffsetBytes ; <nl> <nl> if ( fileOffset < m_fileOffsetStart | | fileOffset > m_fileOffsetEnd ) <nl> { <nl> Sequence < ElemType > TextParser < ElemType > : : LoadSequence ( bool verifyId , const Seque <nl> <nl> size_t bufferOffset = fileOffset - m_fileOffsetStart ; <nl> m_pos = m_bufferStart + bufferOffset ; <nl> - int64_t bytesToRead = sequenceDsc . m_byteSize ; <nl> + size_t bytesToRead = sequenceDsc . m_byteSize ; <nl> <nl> <nl> if ( verifyId ) { <nl> Sequence < ElemType > TextParser < ElemType > : : LoadSequence ( bool verifyId , const Seque <nl> <nl> / / read one whole line of input <nl> template < class ElemType > <nl> - bool TextParser < ElemType > : : ReadRow ( Sequence < ElemType > & sequence , int64_t & bytesToRead ) { <nl> + bool TextParser < ElemType > : : ReadRow ( Sequence < ElemType > & sequence , size_t & bytesToRead ) { <nl> bool found = false ; <nl> while ( bytesToRead & & CanRead ( ) ) <nl> { <nl> bool TextParser < ElemType > : : ReadRow ( Sequence < ElemType > & sequence , int64_t & bytesT <nl> } <nl> <nl> template < class ElemType > <nl> - bool TextParser < ElemType > : : GetInputId ( size_t & id , int64_t & bytesToRead ) <nl> + bool TextParser < ElemType > : : GetInputId ( size_t & id , size_t & bytesToRead ) <nl> { <nl> char * scratchIndex = m_scratch ; <nl> <nl> bool TextParser < ElemType > : : GetInputId ( size_t & id , int64_t & bytesToRead ) <nl> } <nl> <nl> template < class ElemType > <nl> - bool TextParser < ElemType > : : ReadDenseSample ( vector < ElemType > & values , size_t sampleSize , int64_t & bytesToRead ) <nl> + bool TextParser < ElemType > : : ReadDenseSample ( vector < ElemType > & values , size_t sampleSize , size_t & bytesToRead ) <nl> { <nl> size_t counter = 0 ; <nl> ElemType value ; <nl> bool TextParser < ElemType > : : ReadDenseSample ( vector < ElemType > & values , size_t samp <nl> } <nl> <nl> template < class ElemType > <nl> - bool TextParser < ElemType > : : ReadSparseSample ( std : : vector < ElemType > & values , std : : vector < size_t > & indices , int64_t & bytesToRead ) <nl> + bool TextParser < ElemType > : : ReadSparseSample ( std : : vector < ElemType > & values , std : : vector < size_t > & indices , size_t & bytesToRead ) <nl> { <nl> size_t index ; <nl> ElemType value ; <nl> bool TextParser < ElemType > : : ReadSparseSample ( std : : vector < ElemType > & values , std : : <nl> } <nl> <nl> template < class ElemType > <nl> - void TextParser < ElemType > : : SkipToNextValue ( int64_t & bytesToRead ) <nl> + void TextParser < ElemType > : : SkipToNextValue ( size_t & bytesToRead ) <nl> { <nl> while ( bytesToRead & & CanRead ( ) ) <nl> { <nl> void TextParser < ElemType > : : SkipToNextValue ( int64_t & bytesToRead ) <nl> } <nl> <nl> template < class ElemType > <nl> - void TextParser < ElemType > : : SkipToNextInput ( int64_t & bytesToRead ) <nl> + void TextParser < ElemType > : : SkipToNextInput ( size_t & bytesToRead ) <nl> { <nl> while ( bytesToRead & & CanRead ( ) ) <nl> { <nl> void TextParser < ElemType > : : SkipToNextInput ( int64_t & bytesToRead ) <nl> } <nl> <nl> template < class ElemType > <nl> - bool TextParser < ElemType > : : ReadUint64 ( size_t & id , int64_t & bytesToRead ) { <nl> + bool TextParser < ElemType > : : ReadUint64 ( size_t & id , size_t & bytesToRead ) { <nl> id = 0 ; <nl> bool found = false ; <nl> while ( bytesToRead & & CanRead ( ) ) <nl> bool TextParser < ElemType > : : ReadUint64 ( size_t & id , int64_t & bytesToRead ) { <nl> / / cannot be parsed as part of a floating point number . <nl> / / Returns true if parsing was successful . <nl> template < class ElemType > <nl> - bool TextParser < ElemType > : : ReadRealNumber ( ElemType & value , int64_t & bytesToRead ) <nl> + bool TextParser < ElemType > : : ReadRealNumber ( ElemType & value , size_t & bytesToRead ) <nl> { <nl> State state = State : : Init ; <nl> double coefficient = . 0 , number = . 0 , divider = . 0 ; <nl> void TextParser < ElemType > : : SetChunkCacheSize ( unsigned int size ) { <nl> } <nl> <nl> template < class ElemType > <nl> - void TextParser < ElemType > : : SetChunkSize ( int64_t size ) { <nl> - m_chunkSize = size ; <nl> + void TextParser < ElemType > : : SetChunkSize ( size_t size ) { <nl> + m_chunkSizeBytes = size ; <nl> } <nl> <nl> template class TextParser < float > ; <nl> mmm a / Source / Readers / CNTKTextFormatReader / TextParser . h <nl> ppp b / Source / Readers / CNTKTextFormatReader / TextParser . h <nl> struct DenseData : Data < ElemType > <nl> / / capacity = expected number of samples * sample size <nl> DenseData ( size_t capacity ) <nl> { <nl> - m_buffer . reserve ( capacity ) ; <nl> + Data < ElemType > : : m_buffer . reserve ( capacity ) ; <nl> } <nl> } ; <nl> <nl> class TextParser : public DataDeserializerBase { <nl> <nl> char * m_scratch ; / / local buffer for string parsing <nl> <nl> - int64_t m_chunkSize = 0 ; <nl> + size_t m_chunkSizeBytes = 0 ; <nl> unsigned int m_chunkCacheSize = 0 ; / / number of chunks to keep in the memory <nl> unsigned int m_traceLevel = 0 ; <nl> unsigned int m_numAllowedErrors = 0 ; <nl> class TextParser : public DataDeserializerBase { <nl> <nl> void SetFileOffset ( int64_t position ) ; <nl> <nl> - void SkipToNextValue ( int64_t & bytesToRead ) ; <nl> - void SkipToNextInput ( int64_t & bytesToRead ) ; <nl> + void SkipToNextValue ( size_t & bytesToRead ) ; <nl> + void SkipToNextInput ( size_t & bytesToRead ) ; <nl> <nl> bool Fill ( ) ; <nl> <nl> int64_t GetFileOffset ( ) { return m_fileOffsetStart + ( m_pos - m_bufferStart ) ; } <nl> <nl> / / reads an alias / name and converts it to an internal stream id ( = stream index ) . <nl> - bool GetInputId ( size_t & id , int64_t & bytesToRead ) ; <nl> + bool GetInputId ( size_t & id , size_t & bytesToRead ) ; <nl> <nl> - bool ReadRealNumber ( ElemType & value , int64_t & bytesToRead ) ; <nl> + bool ReadRealNumber ( ElemType & value , size_t & bytesToRead ) ; <nl> <nl> - bool ReadUint64 ( size_t & index , int64_t & bytesToRead ) ; <nl> + bool ReadUint64 ( size_t & index , size_t & bytesToRead ) ; <nl> <nl> - bool ReadDenseSample ( std : : vector < ElemType > & values , size_t sampleSize , int64_t & bytesToRead ) ; <nl> + bool ReadDenseSample ( std : : vector < ElemType > & values , size_t sampleSize , size_t & bytesToRead ) ; <nl> <nl> - bool ReadSparseSample ( std : : vector < ElemType > & values , std : : vector < size_t > & indices , int64_t & bytesToRead ) ; <nl> + bool ReadSparseSample ( std : : vector < ElemType > & values , std : : vector < size_t > & indices , size_t & bytesToRead ) ; <nl> <nl> / / read one whole row ( terminated by a row delimiter ) of samples <nl> - bool ReadRow ( Sequence < ElemType > & sequence , int64_t & bytesToRead ) ; <nl> + bool ReadRow ( Sequence < ElemType > & sequence , size_t & bytesToRead ) ; <nl> <nl> bool inline CanRead ( ) { return m_pos ! = m_bufferEnd | | Fill ( ) ; } <nl> <nl> class TextParser : public DataDeserializerBase { <nl> <nl> TextParser ( const std : : wstring & filename , const vector < StreamDescriptor > & streams ) ; <nl> <nl> - TextParser ( const TextParser & ) = delete ; <nl> - TextParser & operator = ( const TextParser & ) = delete ; <nl> + DISABLE_COPY_AND_MOVE ( TextParser ) ; <nl> protected : <nl> void FillSequenceDescriptions ( SequenceDescriptions & timeline ) const override ; <nl> <nl> class TextParser : public DataDeserializerBase { <nl> <nl> void SetSkipSequenceIds ( bool skip ) ; <nl> <nl> - void SetChunkSize ( int64_t size ) ; <nl> + void SetChunkSize ( size_t size ) ; <nl> <nl> void SetChunkCacheSize ( unsigned int size ) ; <nl> } ; <nl> mmm a / Tests / UnitTests / ReaderTests / Config / CNTKTextFormatReader1x100_Config . cntk <nl> ppp b / Tests / UnitTests / ReaderTests / Config / CNTKTextFormatReader1x100_Config . cntk <nl> traceLevel = 1 <nl> # maxErrors = 0 - - default value <nl> traceLevel = 1 <nl> <nl> - chunkSize = 10000 # ~ 3 full sequences ( 30 samples ) <nl> - chunkCacheSize = 5 <nl> + chunkSizeInBytes = 10000 # ~ 3 full sequences ( 30 samples ) <nl> + numChunksToCache = 5 <nl> <nl> input = [ <nl> <nl> mmm a / Tests / UnitTests / ReaderTests / Config / CNTKTextFormatReader1x10_MI_Config . cntk <nl> ppp b / Tests / UnitTests / ReaderTests / Config / CNTKTextFormatReader1x10_MI_Config . cntk <nl> traceLevel = 1 <nl> # maxErrors = 0 - - default value <nl> traceLevel = 1 <nl> <nl> - chunkSize = 50000 # ~ 1 / 2 input size <nl> - chunkCacheSize = 1 <nl> + chunkSizeInBytes = 50000 # ~ 1 / 2 input size <nl> + numChunksToCache = 1 <nl> <nl> input = [ <nl> <nl> mmm a / Tests / UnitTests / ReaderTests / Config / CNTKTextFormatReaderMNIST_Config . cntk <nl> ppp b / Tests / UnitTests / ReaderTests / Config / CNTKTextFormatReaderMNIST_Config . cntk <nl> MNIST_Test = [ <nl> # maxErrors = 0 - - default value <nl> traceLevel = 1 <nl> <nl> - chunkSize = 10000 # should be enough for ~ 10 samples . <nl> - chunkCacheSize = 10 <nl> + chunkSizeInBytes = 10000 # should be enough for ~ 10 samples . <nl> + numChunksToCache = 10 <nl> <nl> input = [ <nl> <nl>
Address CR feedback
microsoft/CNTK
318bb8c02ec8c602542ca9d3edec5e59daac1ca6
2016-03-11T15:06:43Z
mmm a / src / ast / ast - value - factory . cc <nl> ppp b / src / ast / ast - value - factory . cc <nl> void AstRawString : : Internalize ( LocalIsolate * isolate ) { <nl> if ( literal_bytes_ . length ( ) = = 0 ) { <nl> set_string ( isolate - > factory ( ) - > empty_string ( ) ) ; <nl> } else if ( is_one_byte ( ) ) { <nl> - OneByteStringKey key ( hash_field_ , literal_bytes_ ) ; <nl> + OneByteStringKey key ( raw_hash_field_ , literal_bytes_ ) ; <nl> set_string ( isolate - > factory ( ) - > InternalizeStringWithKey ( & key ) ) ; <nl> } else { <nl> - TwoByteStringKey key ( hash_field_ , <nl> + TwoByteStringKey key ( raw_hash_field_ , <nl> Vector < const uint16_t > : : cast ( literal_bytes_ ) ) ; <nl> set_string ( isolate - > factory ( ) - > InternalizeStringWithKey ( & key ) ) ; <nl> } <nl> template EXPORT_TEMPLATE_DEFINE ( <nl> bool AstRawString : : AsArrayIndex ( uint32_t * index ) const { <nl> / / The StringHasher will set up the hash . Bail out early if we know it <nl> / / can ' t be convertible to an array index . <nl> - if ( ( hash_field_ & Name : : kIsNotIntegerIndexMask ) ! = 0 ) return false ; <nl> + if ( ( raw_hash_field_ & Name : : kIsNotIntegerIndexMask ) ! = 0 ) return false ; <nl> if ( length ( ) < = Name : : kMaxCachedArrayIndexLength ) { <nl> - * index = Name : : ArrayIndexValueBits : : decode ( hash_field_ ) ; <nl> + * index = Name : : ArrayIndexValueBits : : decode ( raw_hash_field_ ) ; <nl> return true ; <nl> } <nl> / / Might be an index , but too big to cache it . Do the slow conversion . This <nl> bool AstRawString : : AsArrayIndex ( uint32_t * index ) const { <nl> } <nl> <nl> bool AstRawString : : IsIntegerIndex ( ) const { <nl> - return ( hash_field_ & Name : : kIsNotIntegerIndexMask ) = = 0 ; <nl> + return ( raw_hash_field_ & Name : : kIsNotIntegerIndexMask ) = = 0 ; <nl> } <nl> <nl> bool AstRawString : : IsOneByteEqualTo ( const char * data ) const { <nl> AstStringConstants : : AstStringConstants ( Isolate * isolate , uint64_t hash_seed ) <nl> string_table_ ( ) , <nl> hash_seed_ ( hash_seed ) { <nl> DCHECK_EQ ( ThreadId : : Current ( ) , isolate - > thread_id ( ) ) ; <nl> - # define F ( name , str ) \ <nl> - { \ <nl> - const char * data = str ; \ <nl> - Vector < const uint8_t > literal ( reinterpret_cast < const uint8_t * > ( data ) , \ <nl> - static_cast < int > ( strlen ( data ) ) ) ; \ <nl> - uint32_t hash_field = StringHasher : : HashSequentialString < uint8_t > ( \ <nl> - literal . begin ( ) , literal . length ( ) , hash_seed_ ) ; \ <nl> - name # # _string_ = zone_ . New < AstRawString > ( true , literal , hash_field ) ; \ <nl> - / * The Handle returned by the factory is located on the roots * / \ <nl> - / * array , not on the temporary HandleScope , so this is safe . * / \ <nl> - name # # _string_ - > set_string ( isolate - > factory ( ) - > name # # _string ( ) ) ; \ <nl> - string_table_ . InsertNew ( name # # _string_ , name # # _string_ - > Hash ( ) ) ; \ <nl> + # define F ( name , str ) \ <nl> + { \ <nl> + const char * data = str ; \ <nl> + Vector < const uint8_t > literal ( reinterpret_cast < const uint8_t * > ( data ) , \ <nl> + static_cast < int > ( strlen ( data ) ) ) ; \ <nl> + uint32_t raw_hash_field = StringHasher : : HashSequentialString < uint8_t > ( \ <nl> + literal . begin ( ) , literal . length ( ) , hash_seed_ ) ; \ <nl> + name # # _string_ = zone_ . New < AstRawString > ( true , literal , raw_hash_field ) ; \ <nl> + / * The Handle returned by the factory is located on the roots * / \ <nl> + / * array , not on the temporary HandleScope , so this is safe . * / \ <nl> + name # # _string_ - > set_string ( isolate - > factory ( ) - > name # # _string ( ) ) ; \ <nl> + string_table_ . InsertNew ( name # # _string_ , name # # _string_ - > Hash ( ) ) ; \ <nl> } <nl> AST_STRING_CONSTANTS ( F ) <nl> # undef F <nl> const AstRawString * AstValueFactory : : GetOneByteStringInternal ( <nl> if ( literal . length ( ) = = 1 & & literal [ 0 ] < kMaxOneCharStringValue ) { <nl> int key = literal [ 0 ] ; <nl> if ( V8_UNLIKELY ( one_character_strings_ [ key ] = = nullptr ) ) { <nl> - uint32_t hash_field = StringHasher : : HashSequentialString < uint8_t > ( <nl> + uint32_t raw_hash_field = StringHasher : : HashSequentialString < uint8_t > ( <nl> literal . begin ( ) , literal . length ( ) , hash_seed_ ) ; <nl> - one_character_strings_ [ key ] = GetString ( hash_field , true , literal ) ; <nl> + one_character_strings_ [ key ] = GetString ( raw_hash_field , true , literal ) ; <nl> } <nl> return one_character_strings_ [ key ] ; <nl> } <nl> - uint32_t hash_field = StringHasher : : HashSequentialString < uint8_t > ( <nl> + uint32_t raw_hash_field = StringHasher : : HashSequentialString < uint8_t > ( <nl> literal . begin ( ) , literal . length ( ) , hash_seed_ ) ; <nl> - return GetString ( hash_field , true , literal ) ; <nl> + return GetString ( raw_hash_field , true , literal ) ; <nl> } <nl> <nl> const AstRawString * AstValueFactory : : GetTwoByteStringInternal ( <nl> Vector < const uint16_t > literal ) { <nl> - uint32_t hash_field = StringHasher : : HashSequentialString < uint16_t > ( <nl> + uint32_t raw_hash_field = StringHasher : : HashSequentialString < uint16_t > ( <nl> literal . begin ( ) , literal . length ( ) , hash_seed_ ) ; <nl> - return GetString ( hash_field , false , Vector < const byte > : : cast ( literal ) ) ; <nl> + return GetString ( raw_hash_field , false , Vector < const byte > : : cast ( literal ) ) ; <nl> } <nl> <nl> const AstRawString * AstValueFactory : : GetString ( Handle < String > literal ) { <nl> const AstRawString * AstValueFactory : : GetString ( Handle < String > literal ) { <nl> const AstRawString * AstValueFactory : : CloneFromOtherFactory ( <nl> const AstRawString * raw_string ) { <nl> const AstRawString * result = GetString ( <nl> - raw_string - > hash_field ( ) , raw_string - > is_one_byte ( ) , <nl> + raw_string - > raw_hash_field ( ) , raw_string - > is_one_byte ( ) , <nl> Vector < const byte > ( raw_string - > raw_data ( ) , raw_string - > byte_length ( ) ) ) ; <nl> return result ; <nl> } <nl> template EXPORT_TEMPLATE_DEFINE ( <nl> V8_EXPORT_PRIVATE ) void AstValueFactory : : Internalize ( LocalIsolate * isolate ) ; <nl> <nl> const AstRawString * AstValueFactory : : GetString ( <nl> - uint32_t hash_field , bool is_one_byte , Vector < const byte > literal_bytes ) { <nl> + uint32_t raw_hash_field , bool is_one_byte , <nl> + Vector < const byte > literal_bytes ) { <nl> / / literal_bytes here points to whatever the user passed , and this is OK <nl> / / because we use vector_compare ( which checks the contents ) to compare <nl> / / against the AstRawStrings which are in the string_table_ . We should not <nl> / / return this AstRawString . <nl> - AstRawString key ( is_one_byte , literal_bytes , hash_field ) ; <nl> + AstRawString key ( is_one_byte , literal_bytes , raw_hash_field ) ; <nl> AstRawStringMap : : Entry * entry = string_table_ . LookupOrInsert ( <nl> & key , key . Hash ( ) , <nl> [ & ] ( ) { <nl> const AstRawString * AstValueFactory : : GetString ( <nl> memcpy ( new_literal_bytes , literal_bytes . begin ( ) , length ) ; <nl> AstRawString * new_string = zone ( ) - > New < AstRawString > ( <nl> is_one_byte , Vector < const byte > ( new_literal_bytes , length ) , <nl> - hash_field ) ; <nl> + raw_hash_field ) ; <nl> CHECK_NOT_NULL ( new_string ) ; <nl> AddString ( new_string ) ; <nl> return new_string ; <nl> mmm a / src / ast / ast - value - factory . h <nl> ppp b / src / ast / ast - value - factory . h <nl> class AstRawString final : public ZoneObject { <nl> bool IsPrivateName ( ) const { return length ( ) > 0 & & FirstCharacter ( ) = = ' # ' ; } <nl> <nl> / / For storing AstRawStrings in a hash map . <nl> - uint32_t hash_field ( ) const { return hash_field_ ; } <nl> - uint32_t Hash ( ) const { return hash_field_ > > Name : : kHashShift ; } <nl> + uint32_t raw_hash_field ( ) const { return raw_hash_field_ ; } <nl> + uint32_t Hash ( ) const { return raw_hash_field_ > > Name : : kHashShift ; } <nl> <nl> / / This function can be called after internalizing . <nl> V8_INLINE Handle < String > string ( ) const { <nl> class AstRawString final : public ZoneObject { <nl> <nl> / / Members accessed only by the AstValueFactory & related classes : <nl> AstRawString ( bool is_one_byte , const Vector < const byte > & literal_bytes , <nl> - uint32_t hash_field ) <nl> + uint32_t raw_hash_field ) <nl> : next_ ( nullptr ) , <nl> literal_bytes_ ( literal_bytes ) , <nl> - hash_field_ ( hash_field ) , <nl> + raw_hash_field_ ( raw_hash_field ) , <nl> is_one_byte_ ( is_one_byte ) { } <nl> AstRawString * next ( ) { <nl> DCHECK ( ! has_string_ ) ; <nl> class AstRawString final : public ZoneObject { <nl> } ; <nl> <nl> Vector < const byte > literal_bytes_ ; / / Memory owned by Zone . <nl> - uint32_t hash_field_ ; <nl> + uint32_t raw_hash_field_ ; <nl> bool is_one_byte_ ; <nl> # ifdef DEBUG <nl> / / ( Debug - only : ) Verify the object life - cylce : Some functions may only be <nl> class AstValueFactory { <nl> V8_EXPORT_PRIVATE const AstRawString * GetOneByteStringInternal ( <nl> Vector < const uint8_t > literal ) ; <nl> const AstRawString * GetTwoByteStringInternal ( Vector < const uint16_t > literal ) ; <nl> - const AstRawString * GetString ( uint32_t hash , bool is_one_byte , <nl> + const AstRawString * GetString ( uint32_t raw_hash_field , bool is_one_byte , <nl> Vector < const byte > literal_bytes ) ; <nl> <nl> / / All strings are copied here . <nl> mmm a / src / builtins / builtins - string - gen . cc <nl> ppp b / src / builtins / builtins - string - gen . cc <nl> TNode < String > StringBuiltinsAssembler : : AllocateConsString ( TNode < Uint32T > length , <nl> TNode < HeapObject > result = AllocateInNewSpace ( ConsString : : kSize ) ; <nl> StoreMapNoWriteBarrier ( result , result_map ) ; <nl> StoreObjectFieldNoWriteBarrier ( result , ConsString : : kLengthOffset , length ) ; <nl> - StoreObjectFieldNoWriteBarrier ( result , ConsString : : kHashFieldOffset , <nl> + StoreObjectFieldNoWriteBarrier ( result , ConsString : : kRawHashFieldOffset , <nl> Int32Constant ( String : : kEmptyHashField ) ) ; <nl> StoreObjectFieldNoWriteBarrier ( result , ConsString : : kFirstOffset , left ) ; <nl> StoreObjectFieldNoWriteBarrier ( result , ConsString : : kSecondOffset , right ) ; <nl> mmm a / src / builtins / number . tq <nl> ppp b / src / builtins / number . tq <nl> macro NumberToStringSmi ( x : int32 , radix : int32 ) : String labels Slow { <nl> / / In sync with Factory : : SmiToString : If radix = 10 and positive number , <nl> / / update hash for string . <nl> if ( radix = = 10 ) { <nl> - assert ( strSeq . hash_field = = kNameEmptyHashField ) ; <nl> - strSeq . hash_field = MakeArrayIndexHash ( Unsigned ( x ) , Unsigned ( length ) ) ; <nl> + assert ( strSeq . raw_hash_field = = kNameEmptyHashField ) ; <nl> + strSeq . raw_hash_field = MakeArrayIndexHash ( Unsigned ( x ) , Unsigned ( length ) ) ; <nl> } <nl> } <nl> return strSeq ; <nl> transitioning javascript builtin NumberParseFloat ( <nl> } <nl> } label String ( s : String ) { <nl> / / Check if the string is a cached array index . <nl> - const hash : NameHash = s . hash_field ; <nl> + const hash : NameHash = s . raw_hash_field ; <nl> if ( ! hash . is_not_integer_index_mask & & <nl> hash . array_index_length < kMaxCachedArrayIndexLength ) { <nl> const arrayIndex : uint32 = hash . array_index_value ; <nl> transitioning builtin ParseInt ( implicit context : Context ) ( <nl> return ChangeInt32ToTagged ( i ) ; <nl> } label String ( s : String ) { <nl> / / Check if the string is a cached array index . <nl> - const hash : NameHash = s . hash_field ; <nl> + const hash : NameHash = s . raw_hash_field ; <nl> if ( ! hash . is_not_integer_index_mask & & <nl> hash . array_index_length < kMaxCachedArrayIndexLength ) { <nl> const arrayIndex : uint32 = hash . array_index_value ; <nl> mmm a / src / codegen / code - stub - assembler . cc <nl> ppp b / src / codegen / code - stub - assembler . cc <nl> TNode < IntPtrT > CodeStubAssembler : : LoadJSReceiverIdentityHash ( <nl> } <nl> <nl> TNode < Uint32T > CodeStubAssembler : : LoadNameHashAssumeComputed ( TNode < Name > name ) { <nl> - TNode < Uint32T > hash_field = LoadNameHashField ( name ) ; <nl> + TNode < Uint32T > hash_field = LoadNameRawHashField ( name ) ; <nl> CSA_ASSERT ( this , IsClearWord32 ( hash_field , Name : : kHashNotComputedMask ) ) ; <nl> return Unsigned ( Word32Shr ( hash_field , Int32Constant ( Name : : kHashShift ) ) ) ; <nl> } <nl> <nl> TNode < Uint32T > CodeStubAssembler : : LoadNameHash ( TNode < Name > name , <nl> Label * if_hash_not_computed ) { <nl> - TNode < Uint32T > hash_field = LoadNameHashField ( name ) ; <nl> + TNode < Uint32T > raw_hash_field = LoadNameRawHashField ( name ) ; <nl> if ( if_hash_not_computed ! = nullptr ) { <nl> - GotoIf ( IsSetWord32 ( hash_field , Name : : kHashNotComputedMask ) , <nl> + GotoIf ( IsSetWord32 ( raw_hash_field , Name : : kHashNotComputedMask ) , <nl> if_hash_not_computed ) ; <nl> } <nl> - return Unsigned ( Word32Shr ( hash_field , Int32Constant ( Name : : kHashShift ) ) ) ; <nl> + return Unsigned ( Word32Shr ( raw_hash_field , Int32Constant ( Name : : kHashShift ) ) ) ; <nl> } <nl> <nl> TNode < Smi > CodeStubAssembler : : LoadStringLengthAsSmi ( TNode < String > string ) { <nl> TNode < String > CodeStubAssembler : : AllocateSeqOneByteString ( <nl> StoreMapNoWriteBarrier ( result , RootIndex : : kOneByteStringMap ) ; <nl> StoreObjectFieldNoWriteBarrier ( result , SeqOneByteString : : kLengthOffset , <nl> Uint32Constant ( length ) ) ; <nl> - StoreObjectFieldNoWriteBarrier ( result , SeqOneByteString : : kHashFieldOffset , <nl> + StoreObjectFieldNoWriteBarrier ( result , SeqOneByteString : : kRawHashFieldOffset , <nl> Int32Constant ( String : : kEmptyHashField ) ) ; <nl> return CAST ( result ) ; <nl> } <nl> TNode < String > CodeStubAssembler : : AllocateSeqTwoByteString ( <nl> StoreMapNoWriteBarrier ( result , RootIndex : : kStringMap ) ; <nl> StoreObjectFieldNoWriteBarrier ( result , SeqTwoByteString : : kLengthOffset , <nl> Uint32Constant ( length ) ) ; <nl> - StoreObjectFieldNoWriteBarrier ( result , SeqTwoByteString : : kHashFieldOffset , <nl> + StoreObjectFieldNoWriteBarrier ( result , SeqTwoByteString : : kRawHashFieldOffset , <nl> Int32Constant ( String : : kEmptyHashField ) ) ; <nl> return CAST ( result ) ; <nl> } <nl> TNode < String > CodeStubAssembler : : AllocateSlicedString ( RootIndex map_root_index , <nl> TNode < HeapObject > result = Allocate ( SlicedString : : kSize ) ; <nl> DCHECK ( RootsTable : : IsImmortalImmovable ( map_root_index ) ) ; <nl> StoreMapNoWriteBarrier ( result , map_root_index ) ; <nl> - StoreObjectFieldNoWriteBarrier ( result , SlicedString : : kHashFieldOffset , <nl> + StoreObjectFieldNoWriteBarrier ( result , SlicedString : : kRawHashFieldOffset , <nl> Int32Constant ( String : : kEmptyHashField ) ) ; <nl> StoreObjectFieldNoWriteBarrier ( result , SlicedString : : kLengthOffset , length ) ; <nl> StoreObjectFieldNoWriteBarrier ( result , SlicedString : : kParentOffset , parent ) ; <nl> TNode < BoolT > CodeStubAssembler : : IsUniqueNameNoIndex ( TNode < HeapObject > object ) { <nl> return Select < BoolT > ( <nl> IsInternalizedStringInstanceType ( instance_type ) , <nl> [ = ] { <nl> - return IsSetWord32 ( LoadNameHashField ( CAST ( object ) ) , <nl> + return IsSetWord32 ( LoadNameRawHashField ( CAST ( object ) ) , <nl> Name : : kIsNotIntegerIndexMask ) ; <nl> } , <nl> [ = ] { return IsSymbolInstanceType ( instance_type ) ; } ) ; <nl> TNode < BoolT > CodeStubAssembler : : IsUniqueNameNoCachedIndex ( <nl> return Select < BoolT > ( <nl> IsInternalizedStringInstanceType ( instance_type ) , <nl> [ = ] { <nl> - return IsSetWord32 ( LoadNameHashField ( CAST ( object ) ) , <nl> + return IsSetWord32 ( LoadNameRawHashField ( CAST ( object ) ) , <nl> Name : : kDoesNotContainCachedArrayIndexMask ) ; <nl> } , <nl> [ = ] { return IsSymbolInstanceType ( instance_type ) ; } ) ; <nl> TNode < Number > CodeStubAssembler : : StringToNumber ( TNode < String > input ) { <nl> TVARIABLE ( Number , var_result ) ; <nl> <nl> / / Check if string has a cached array index . <nl> - TNode < Uint32T > hash = LoadNameHashField ( input ) ; <nl> - GotoIf ( IsSetWord32 ( hash , Name : : kDoesNotContainCachedArrayIndexMask ) , <nl> + TNode < Uint32T > raw_hash_field = LoadNameRawHashField ( input ) ; <nl> + GotoIf ( IsSetWord32 ( raw_hash_field , Name : : kDoesNotContainCachedArrayIndexMask ) , <nl> & runtime ) ; <nl> <nl> - var_result = <nl> - SmiTag ( Signed ( DecodeWordFromWord32 < String : : ArrayIndexValueBits > ( hash ) ) ) ; <nl> + var_result = SmiTag ( Signed ( <nl> + DecodeWordFromWord32 < String : : ArrayIndexValueBits > ( raw_hash_field ) ) ) ; <nl> Goto ( & end ) ; <nl> <nl> BIND ( & runtime ) ; <nl> void CodeStubAssembler : : TryToName ( SloppyTNode < Object > key , Label * if_keyisindex , <nl> { <nl> Label if_thinstring ( this ) , if_has_cached_index ( this ) ; <nl> <nl> - TNode < Uint32T > hash = LoadNameHashField ( CAST ( key ) ) ; <nl> - GotoIf ( IsClearWord32 ( hash , Name : : kDoesNotContainCachedArrayIndexMask ) , <nl> + TNode < Uint32T > raw_hash_field = LoadNameRawHashField ( CAST ( key ) ) ; <nl> + GotoIf ( IsClearWord32 ( raw_hash_field , <nl> + Name : : kDoesNotContainCachedArrayIndexMask ) , <nl> & if_has_cached_index ) ; <nl> / / No cached array index . If the string knows that it contains an index , <nl> / / then it must be an uncacheable index . Handle this case in the runtime . <nl> - GotoIf ( IsClearWord32 ( hash , Name : : kIsNotIntegerIndexMask ) , if_bailout ) ; <nl> + GotoIf ( IsClearWord32 ( raw_hash_field , Name : : kIsNotIntegerIndexMask ) , <nl> + if_bailout ) ; <nl> <nl> GotoIf ( InstanceTypeEqual ( var_instance_type . value ( ) , THIN_STRING_TYPE ) , <nl> & if_thinstring ) ; <nl> void CodeStubAssembler : : TryToName ( SloppyTNode < Object > key , Label * if_keyisindex , <nl> <nl> BIND ( & if_has_cached_index ) ; <nl> { <nl> - TNode < IntPtrT > index = <nl> - Signed ( DecodeWordFromWord32 < String : : ArrayIndexValueBits > ( hash ) ) ; <nl> + TNode < IntPtrT > index = Signed ( <nl> + DecodeWordFromWord32 < String : : ArrayIndexValueBits > ( raw_hash_field ) ) ; <nl> CSA_ASSERT ( this , IntPtrLessThan ( index , IntPtrConstant ( INT_MAX ) ) ) ; <nl> * var_index = index ; <nl> Goto ( if_keyisindex ) ; <nl> mmm a / src / compiler / access - builder . cc <nl> ppp b / src / compiler / access - builder . cc <nl> FieldAccess AccessBuilder : : ForModuleRegularImports ( ) { <nl> } <nl> <nl> / / static <nl> - FieldAccess AccessBuilder : : ForNameHashField ( ) { <nl> - FieldAccess access = { kTaggedBase , Name : : kHashFieldOffset , <nl> + FieldAccess AccessBuilder : : ForNameRawHashField ( ) { <nl> + FieldAccess access = { kTaggedBase , Name : : kRawHashFieldOffset , <nl> Handle < Name > ( ) , MaybeHandle < Map > ( ) , <nl> Type : : Unsigned32 ( ) , MachineType : : Uint32 ( ) , <nl> kNoWriteBarrier } ; <nl> mmm a / src / compiler / access - builder . h <nl> ppp b / src / compiler / access - builder . h <nl> class V8_EXPORT_PRIVATE AccessBuilder final <nl> / / Provides access to Module : : regular_imports ( ) field . <nl> static FieldAccess ForModuleRegularImports ( ) ; <nl> <nl> - / / Provides access to Name : : hash_field ( ) field . <nl> - static FieldAccess ForNameHashField ( ) ; <nl> + / / Provides access to Name : : raw_hash_field ( ) field . <nl> + static FieldAccess ForNameRawHashField ( ) ; <nl> <nl> / / Provides access to String : : length ( ) field . <nl> static FieldAccess ForStringLength ( ) ; <nl> mmm a / src / compiler / effect - control - linearizer . cc <nl> ppp b / src / compiler / effect - control - linearizer . cc <nl> Node * EffectControlLinearizer : : LowerNewConsString ( Node * node ) { <nl> Node * result = <nl> __ Allocate ( AllocationType : : kYoung , __ IntPtrConstant ( ConsString : : kSize ) ) ; <nl> __ StoreField ( AccessBuilder : : ForMap ( ) , result , result_map ) ; <nl> - __ StoreField ( AccessBuilder : : ForNameHashField ( ) , result , <nl> + __ StoreField ( AccessBuilder : : ForNameRawHashField ( ) , result , <nl> __ Int32Constant ( Name : : kEmptyHashField ) ) ; <nl> __ StoreField ( AccessBuilder : : ForStringLength ( ) , result , length ) ; <nl> __ StoreField ( AccessBuilder : : ForConsStringFirst ( ) , result , first ) ; <nl> Node * EffectControlLinearizer : : LowerStringFromSingleCharCode ( Node * node ) { <nl> __ IntPtrConstant ( SeqOneByteString : : SizeFor ( 1 ) ) ) ; <nl> __ StoreField ( AccessBuilder : : ForMap ( ) , vtrue2 , <nl> __ HeapConstant ( factory ( ) - > one_byte_string_map ( ) ) ) ; <nl> - __ StoreField ( AccessBuilder : : ForNameHashField ( ) , vtrue2 , <nl> + __ StoreField ( AccessBuilder : : ForNameRawHashField ( ) , vtrue2 , <nl> __ Int32Constant ( Name : : kEmptyHashField ) ) ; <nl> __ StoreField ( AccessBuilder : : ForStringLength ( ) , vtrue2 , <nl> __ Int32Constant ( 1 ) ) ; <nl> Node * EffectControlLinearizer : : LowerStringFromSingleCharCode ( Node * node ) { <nl> __ IntPtrConstant ( SeqTwoByteString : : SizeFor ( 1 ) ) ) ; <nl> __ StoreField ( AccessBuilder : : ForMap ( ) , vfalse1 , <nl> __ HeapConstant ( factory ( ) - > string_map ( ) ) ) ; <nl> - __ StoreField ( AccessBuilder : : ForNameHashField ( ) , vfalse1 , <nl> + __ StoreField ( AccessBuilder : : ForNameRawHashField ( ) , vfalse1 , <nl> __ Int32Constant ( Name : : kEmptyHashField ) ) ; <nl> __ StoreField ( AccessBuilder : : ForStringLength ( ) , vfalse1 , <nl> __ Int32Constant ( 1 ) ) ; <nl> Node * EffectControlLinearizer : : LowerStringFromSingleCodePoint ( Node * node ) { <nl> __ IntPtrConstant ( SeqOneByteString : : SizeFor ( 1 ) ) ) ; <nl> __ StoreField ( AccessBuilder : : ForMap ( ) , vtrue2 , <nl> __ HeapConstant ( factory ( ) - > one_byte_string_map ( ) ) ) ; <nl> - __ StoreField ( AccessBuilder : : ForNameHashField ( ) , vtrue2 , <nl> + __ StoreField ( AccessBuilder : : ForNameRawHashField ( ) , vtrue2 , <nl> __ Int32Constant ( Name : : kEmptyHashField ) ) ; <nl> __ StoreField ( AccessBuilder : : ForStringLength ( ) , vtrue2 , <nl> __ Int32Constant ( 1 ) ) ; <nl> Node * EffectControlLinearizer : : LowerStringFromSingleCodePoint ( Node * node ) { <nl> __ IntPtrConstant ( SeqTwoByteString : : SizeFor ( 1 ) ) ) ; <nl> __ StoreField ( AccessBuilder : : ForMap ( ) , vfalse1 , <nl> __ HeapConstant ( factory ( ) - > string_map ( ) ) ) ; <nl> - __ StoreField ( AccessBuilder : : ForNameHashField ( ) , vfalse1 , <nl> + __ StoreField ( AccessBuilder : : ForNameRawHashField ( ) , vfalse1 , <nl> __ IntPtrConstant ( Name : : kEmptyHashField ) ) ; <nl> __ StoreField ( AccessBuilder : : ForStringLength ( ) , vfalse1 , <nl> __ Int32Constant ( 1 ) ) ; <nl> Node * EffectControlLinearizer : : LowerStringFromSingleCodePoint ( Node * node ) { <nl> __ IntPtrConstant ( SeqTwoByteString : : SizeFor ( 2 ) ) ) ; <nl> __ StoreField ( AccessBuilder : : ForMap ( ) , vfalse0 , <nl> __ HeapConstant ( factory ( ) - > string_map ( ) ) ) ; <nl> - __ StoreField ( AccessBuilder : : ForNameHashField ( ) , vfalse0 , <nl> + __ StoreField ( AccessBuilder : : ForNameRawHashField ( ) , vfalse0 , <nl> __ Int32Constant ( Name : : kEmptyHashField ) ) ; <nl> __ StoreField ( AccessBuilder : : ForStringLength ( ) , vfalse0 , <nl> __ Int32Constant ( 2 ) ) ; <nl> mmm a / src / diagnostics / objects - printer . cc <nl> ppp b / src / diagnostics / objects - printer . cc <nl> void JSRegExpStringIterator : : JSRegExpStringIteratorPrint ( <nl> <nl> void Symbol : : SymbolPrint ( std : : ostream & os ) { / / NOLINT <nl> PrintHeader ( os , " Symbol " ) ; <nl> - os < < " \ n - hash : " < < Hash ( ) ; <nl> + os < < " \ n - hash : " < < hash ( ) ; <nl> os < < " \ n - description : " < < Brief ( description ( ) ) ; <nl> if ( description ( ) . IsUndefined ( ) ) { <nl> os < < " ( " < < PrivateSymbolToName ( ) < < " ) " ; <nl> mmm a / src / heap / factory - base . cc <nl> ppp b / src / heap / factory - base . cc <nl> Handle < String > FactoryBase < Impl > : : InternalizeString ( <nl> <nl> template < typename Impl > <nl> Handle < SeqOneByteString > FactoryBase < Impl > : : NewOneByteInternalizedString ( <nl> - const Vector < const uint8_t > & str , uint32_t hash_field ) { <nl> + const Vector < const uint8_t > & str , uint32_t raw_hash_field ) { <nl> Handle < SeqOneByteString > result = <nl> - AllocateRawOneByteInternalizedString ( str . length ( ) , hash_field ) ; <nl> + AllocateRawOneByteInternalizedString ( str . length ( ) , raw_hash_field ) ; <nl> DisallowHeapAllocation no_gc ; <nl> MemCopy ( result - > GetChars ( no_gc ) , str . begin ( ) , str . length ( ) ) ; <nl> return result ; <nl> Handle < SeqOneByteString > FactoryBase < Impl > : : NewOneByteInternalizedString ( <nl> <nl> template < typename Impl > <nl> Handle < SeqTwoByteString > FactoryBase < Impl > : : NewTwoByteInternalizedString ( <nl> - const Vector < const uc16 > & str , uint32_t hash_field ) { <nl> + const Vector < const uc16 > & str , uint32_t raw_hash_field ) { <nl> Handle < SeqTwoByteString > result = <nl> - AllocateRawTwoByteInternalizedString ( str . length ( ) , hash_field ) ; <nl> + AllocateRawTwoByteInternalizedString ( str . length ( ) , raw_hash_field ) ; <nl> DisallowHeapAllocation no_gc ; <nl> MemCopy ( result - > GetChars ( no_gc ) , str . begin ( ) , str . length ( ) * kUC16Size ) ; <nl> return result ; <nl> MaybeHandle < SeqOneByteString > FactoryBase < Impl > : : NewRawOneByteString ( <nl> Handle < SeqOneByteString > string = <nl> handle ( SeqOneByteString : : cast ( result ) , isolate ( ) ) ; <nl> string - > set_length ( length ) ; <nl> - string - > set_hash_field ( String : : kEmptyHashField ) ; <nl> + string - > set_raw_hash_field ( String : : kEmptyHashField ) ; <nl> DCHECK_EQ ( size , string - > Size ( ) ) ; <nl> return string ; <nl> } <nl> MaybeHandle < SeqTwoByteString > FactoryBase < Impl > : : NewRawTwoByteString ( <nl> Handle < SeqTwoByteString > string = <nl> handle ( SeqTwoByteString : : cast ( result ) , isolate ( ) ) ; <nl> string - > set_length ( length ) ; <nl> - string - > set_hash_field ( String : : kEmptyHashField ) ; <nl> + string - > set_raw_hash_field ( String : : kEmptyHashField ) ; <nl> DCHECK_EQ ( size , string - > Size ( ) ) ; <nl> return string ; <nl> } <nl> Handle < String > FactoryBase < Impl > : : NewConsString ( Handle < String > left , <nl> DisallowHeapAllocation no_gc ; <nl> WriteBarrierMode mode = result - > GetWriteBarrierMode ( no_gc ) ; <nl> <nl> - result - > set_hash_field ( String : : kEmptyHashField ) ; <nl> + result - > set_raw_hash_field ( String : : kEmptyHashField ) ; <nl> result - > set_length ( length ) ; <nl> result - > set_first ( * left , mode ) ; <nl> result - > set_second ( * right , mode ) ; <nl> Handle < ClassPositions > FactoryBase < Impl > : : NewClassPositions ( int start , <nl> <nl> template < typename Impl > <nl> Handle < SeqOneByteString > <nl> - FactoryBase < Impl > : : AllocateRawOneByteInternalizedString ( int length , <nl> - uint32_t hash_field ) { <nl> + FactoryBase < Impl > : : AllocateRawOneByteInternalizedString ( <nl> + int length , uint32_t raw_hash_field ) { <nl> CHECK_GE ( String : : kMaxLength , length ) ; <nl> / / The canonical empty_string is the only zero - length string we allow . <nl> DCHECK_IMPLIES ( length = = 0 , ! impl ( ) - > EmptyStringRootIsInitialized ( ) ) ; <nl> FactoryBase < Impl > : : AllocateRawOneByteInternalizedString ( int length , <nl> Handle < SeqOneByteString > answer = <nl> handle ( SeqOneByteString : : cast ( result ) , isolate ( ) ) ; <nl> answer - > set_length ( length ) ; <nl> - answer - > set_hash_field ( hash_field ) ; <nl> + answer - > set_raw_hash_field ( raw_hash_field ) ; <nl> DCHECK_EQ ( size , answer - > Size ( ) ) ; <nl> return answer ; <nl> } <nl> <nl> template < typename Impl > <nl> Handle < SeqTwoByteString > <nl> - FactoryBase < Impl > : : AllocateRawTwoByteInternalizedString ( int length , <nl> - uint32_t hash_field ) { <nl> + FactoryBase < Impl > : : AllocateRawTwoByteInternalizedString ( <nl> + int length , uint32_t raw_hash_field ) { <nl> CHECK_GE ( String : : kMaxLength , length ) ; <nl> DCHECK_NE ( 0 , length ) ; / / Use Heap : : empty_string ( ) instead . <nl> <nl> FactoryBase < Impl > : : AllocateRawTwoByteInternalizedString ( int length , <nl> Handle < SeqTwoByteString > answer = <nl> handle ( SeqTwoByteString : : cast ( result ) , isolate ( ) ) ; <nl> answer - > set_length ( length ) ; <nl> - answer - > set_hash_field ( hash_field ) ; <nl> + answer - > set_raw_hash_field ( raw_hash_field ) ; <nl> DCHECK_EQ ( size , result . Size ( ) ) ; <nl> return answer ; <nl> } <nl> mmm a / src / heap / factory - base . h <nl> ppp b / src / heap / factory - base . h <nl> class EXPORT_TEMPLATE_DECLARE ( V8_EXPORT_PRIVATE ) FactoryBase { <nl> Handle < String > InternalizeStringWithKey ( StringTableKey * key ) ; <nl> <nl> Handle < SeqOneByteString > NewOneByteInternalizedString ( <nl> - const Vector < const uint8_t > & str , uint32_t hash_field ) ; <nl> + const Vector < const uint8_t > & str , uint32_t raw_hash_field ) ; <nl> Handle < SeqTwoByteString > NewTwoByteInternalizedString ( <nl> - const Vector < const uc16 > & str , uint32_t hash_field ) ; <nl> + const Vector < const uc16 > & str , uint32_t raw_hash_field ) ; <nl> <nl> Handle < SeqOneByteString > AllocateRawOneByteInternalizedString ( <nl> - int length , uint32_t hash_field ) ; <nl> + int length , uint32_t raw_hash_field ) ; <nl> Handle < SeqTwoByteString > AllocateRawTwoByteInternalizedString ( <nl> - int length , uint32_t hash_field ) ; <nl> + int length , uint32_t raw_hash_field ) ; <nl> <nl> / / Allocates and partially initializes an one - byte or two - byte String . The <nl> / / characters of the string are uninitialized . Currently used in regexp code <nl> mmm a / src / heap / factory . cc <nl> ppp b / src / heap / factory . cc <nl> Handle < String > Factory : : AllocateInternalizedStringImpl ( T t , int chars , <nl> map ) ; <nl> Handle < String > answer ( String : : cast ( result ) , isolate ( ) ) ; <nl> answer - > set_length ( chars ) ; <nl> - answer - > set_hash_field ( hash_field ) ; <nl> + answer - > set_raw_hash_field ( hash_field ) ; <nl> DCHECK_EQ ( size , answer - > Size ( ) ) ; <nl> DisallowHeapAllocation no_gc ; <nl> <nl> Handle < StringClass > Factory : : InternalizeExternalString ( Handle < String > string ) { <nl> StringClass : : cast ( New ( map , AllocationType : : kOld ) ) , isolate ( ) ) ; <nl> external_string - > AllocateExternalPointerEntries ( isolate ( ) ) ; <nl> external_string - > set_length ( cast_string - > length ( ) ) ; <nl> - external_string - > set_hash_field ( cast_string - > hash_field ( ) ) ; <nl> + external_string - > set_raw_hash_field ( cast_string - > raw_hash_field ( ) ) ; <nl> external_string - > SetResource ( isolate ( ) , nullptr ) ; <nl> isolate ( ) - > heap ( ) - > RegisterExternalString ( * external_string ) ; <nl> return external_string ; <nl> Handle < String > Factory : : NewProperSubString ( Handle < String > str , int begin , <nl> Handle < SlicedString > slice ( <nl> SlicedString : : cast ( New ( map , AllocationType : : kYoung ) ) , isolate ( ) ) ; <nl> <nl> - slice - > set_hash_field ( String : : kEmptyHashField ) ; <nl> + slice - > set_raw_hash_field ( String : : kEmptyHashField ) ; <nl> slice - > set_length ( length ) ; <nl> slice - > set_parent ( * str ) ; <nl> slice - > set_offset ( offset ) ; <nl> MaybeHandle < String > Factory : : NewExternalStringFromOneByte ( <nl> ExternalOneByteString : : cast ( New ( map , AllocationType : : kOld ) ) , isolate ( ) ) ; <nl> external_string - > AllocateExternalPointerEntries ( isolate ( ) ) ; <nl> external_string - > set_length ( static_cast < int > ( length ) ) ; <nl> - external_string - > set_hash_field ( String : : kEmptyHashField ) ; <nl> + external_string - > set_raw_hash_field ( String : : kEmptyHashField ) ; <nl> external_string - > SetResource ( isolate ( ) , resource ) ; <nl> isolate ( ) - > heap ( ) - > RegisterExternalString ( * external_string ) ; <nl> <nl> MaybeHandle < String > Factory : : NewExternalStringFromTwoByte ( <nl> ExternalTwoByteString : : cast ( New ( map , AllocationType : : kOld ) ) , isolate ( ) ) ; <nl> external_string - > AllocateExternalPointerEntries ( isolate ( ) ) ; <nl> external_string - > set_length ( static_cast < int > ( length ) ) ; <nl> - external_string - > set_hash_field ( String : : kEmptyHashField ) ; <nl> + external_string - > set_raw_hash_field ( String : : kEmptyHashField ) ; <nl> external_string - > SetResource ( isolate ( ) , resource ) ; <nl> isolate ( ) - > heap ( ) - > RegisterExternalString ( * external_string ) ; <nl> <nl> Handle < Symbol > Factory : : NewSymbol ( AllocationType allocation ) { <nl> int hash = isolate ( ) - > GenerateIdentityHash ( Name : : kHashBitMask ) ; <nl> <nl> Handle < Symbol > symbol ( Symbol : : cast ( result ) , isolate ( ) ) ; <nl> - symbol - > set_hash_field ( Name : : kIsNotIntegerIndexMask | <nl> - ( hash < < Name : : kHashShift ) ) ; <nl> + symbol - > set_raw_hash_field ( Name : : kIsNotIntegerIndexMask | <nl> + ( hash < < Name : : kHashShift ) ) ; <nl> symbol - > set_description ( * undefined_value ( ) ) ; <nl> symbol - > set_flags ( 0 ) ; <nl> DCHECK ( ! symbol - > is_private ( ) ) ; <nl> inline Handle < String > Factory : : SmiToString ( Smi number , NumberCacheMode mode ) { <nl> / / Compute the hash here ( rather than letting the caller take care of it ) so <nl> / / that the " cache hit " case above doesn ' t have to bother with it . <nl> STATIC_ASSERT ( Smi : : kMaxValue < = std : : numeric_limits < uint32_t > : : max ( ) ) ; <nl> - if ( result - > hash_field ( ) = = String : : kEmptyHashField & & number . value ( ) > = 0 ) { <nl> - uint32_t field = StringHasher : : MakeArrayIndexHash ( <nl> + if ( result - > raw_hash_field ( ) = = String : : kEmptyHashField & & <nl> + number . value ( ) > = 0 ) { <nl> + uint32_t raw_hash_field = StringHasher : : MakeArrayIndexHash ( <nl> static_cast < uint32_t > ( number . value ( ) ) , result - > length ( ) ) ; <nl> - result - > set_hash_field ( field ) ; <nl> + result - > set_raw_hash_field ( raw_hash_field ) ; <nl> } <nl> return result ; <nl> } <nl> Handle < String > Factory : : SizeToString ( size_t value , bool check_cache ) { <nl> result = NewStringFromAsciiChecked ( string ) ; <nl> } <nl> if ( value < = JSArray : : kMaxArrayIndex & & <nl> - result - > hash_field ( ) = = String : : kEmptyHashField ) { <nl> - uint32_t field = StringHasher : : MakeArrayIndexHash ( <nl> + result - > raw_hash_field ( ) = = String : : kEmptyHashField ) { <nl> + uint32_t raw_hash_field = StringHasher : : MakeArrayIndexHash ( <nl> static_cast < uint32_t > ( value ) , result - > length ( ) ) ; <nl> - result - > set_hash_field ( field ) ; <nl> + result - > set_raw_hash_field ( raw_hash_field ) ; <nl> } <nl> return result ; <nl> } <nl> mmm a / src / ic / accessor - assembler . cc <nl> ppp b / src / ic / accessor - assembler . cc <nl> enum AccessorAssembler : : StubCacheTable : int { <nl> TNode < IntPtrT > AccessorAssembler : : StubCachePrimaryOffset ( TNode < Name > name , <nl> TNode < Map > map ) { <nl> / / Compute the hash of the name ( use entire hash field ) . <nl> - TNode < Uint32T > hash_field = LoadNameHashField ( name ) ; <nl> + TNode < Uint32T > raw_hash_field = LoadNameRawHashField ( name ) ; <nl> CSA_ASSERT ( this , <nl> - Word32Equal ( Word32And ( hash_field , <nl> + Word32Equal ( Word32And ( raw_hash_field , <nl> Int32Constant ( Name : : kHashNotComputedMask ) ) , <nl> Int32Constant ( 0 ) ) ) ; <nl> <nl> TNode < IntPtrT > AccessorAssembler : : StubCachePrimaryOffset ( TNode < Name > name , <nl> TNode < Int32T > map32 = TruncateIntPtrToInt32 ( UncheckedCast < IntPtrT > ( <nl> WordXor ( map_word , WordShr ( map_word , StubCache : : kMapKeyShift ) ) ) ) ; <nl> / / Base the offset on a simple combination of name and map . <nl> - TNode < Word32T > hash = Int32Add ( hash_field , map32 ) ; <nl> + TNode < Word32T > hash = Int32Add ( raw_hash_field , map32 ) ; <nl> uint32_t mask = ( StubCache : : kPrimaryTableSize - 1 ) <nl> < < StubCache : : kCacheIndexShift ; <nl> TNode < UintPtrT > result = <nl> mmm a / src / ic / stub - cache . cc <nl> ppp b / src / ic / stub - cache . cc <nl> void StubCache : : Initialize ( ) { <nl> int StubCache : : PrimaryOffset ( Name name , Map map ) { <nl> / / Compute the hash of the name ( use entire hash field ) . <nl> DCHECK ( name . HasHashCode ( ) ) ; <nl> - uint32_t field = name . hash_field ( ) ; <nl> + uint32_t field = name . raw_hash_field ( ) ; <nl> / / Using only the low bits in 64 - bit mode is unlikely to increase the <nl> / / risk of collision even if the heap is spread over an area larger than <nl> / / 4Gb ( and not at all if it isn ' t ) . <nl> mmm a / src / objects / lookup - cache - inl . h <nl> ppp b / src / objects / lookup - cache - inl . h <nl> int DescriptorLookupCache : : Hash ( Map source , Name name ) { <nl> DCHECK ( name . IsUniqueName ( ) ) ; <nl> / / Uses only lower 32 bits if pointers are larger . <nl> uint32_t source_hash = static_cast < uint32_t > ( source . ptr ( ) ) > > kTaggedSizeLog2 ; <nl> - uint32_t name_hash = name . hash_field ( ) ; <nl> + uint32_t name_hash = name . hash ( ) ; <nl> return ( source_hash ^ name_hash ) % kLength ; <nl> } <nl> <nl> mmm a / src / objects / name - inl . h <nl> ppp b / src / objects / name - inl . h <nl> bool Name : : IsHashFieldComputed ( uint32_t field ) { <nl> return ( field & kHashNotComputedMask ) = = 0 ; <nl> } <nl> <nl> - bool Name : : HasHashCode ( ) { return IsHashFieldComputed ( hash_field ( ) ) ; } <nl> + bool Name : : HasHashCode ( ) { return IsHashFieldComputed ( raw_hash_field ( ) ) ; } <nl> <nl> uint32_t Name : : Hash ( ) { <nl> / / Fast case : has hash code already been computed ? <nl> - uint32_t field = hash_field ( ) ; <nl> + uint32_t field = raw_hash_field ( ) ; <nl> if ( IsHashFieldComputed ( field ) ) return field > > kHashShift ; <nl> / / Slow case : compute hash code and set it . Has to be a string . <nl> return String : : cast ( * this ) . ComputeAndSetHash ( ) ; <nl> } <nl> <nl> uint32_t Name : : hash ( ) const { <nl> - uint32_t field = hash_field ( ) ; <nl> + uint32_t field = raw_hash_field ( ) ; <nl> DCHECK ( IsHashFieldComputed ( field ) ) ; <nl> return field > > kHashShift ; <nl> } <nl> bool Name : : AsIntegerIndex ( size_t * index ) { <nl> } <nl> <nl> / / static <nl> - bool Name : : ContainsCachedArrayIndex ( uint32_t hash ) { <nl> - return ( hash & Name : : kDoesNotContainCachedArrayIndexMask ) = = 0 ; <nl> + bool Name : : ContainsCachedArrayIndex ( uint32_t raw_hash_field ) { <nl> + return ( raw_hash_field & Name : : kDoesNotContainCachedArrayIndexMask ) = = 0 ; <nl> } <nl> <nl> } / / namespace internal <nl> mmm a / src / objects / name . tq <nl> ppp b / src / objects / name . tq <nl> <nl> @ abstract <nl> @ generateCppClass <nl> extern class Name extends PrimitiveHeapObject { <nl> - hash_field : NameHash ; <nl> + raw_hash_field : NameHash ; <nl> } <nl> <nl> bitfield struct NameHash extends uint32 { <nl> mmm a / src / objects / string - inl . h <nl> ppp b / src / objects / string - inl . h <nl> class SequentialStringKey final : public StringTableKey { <nl> chars . begin ( ) , chars . length ( ) , seed ) , <nl> chars , convert ) { } <nl> <nl> - SequentialStringKey ( int hash , const Vector < const Char > & chars , <nl> + SequentialStringKey ( int raw_hash_field , const Vector < const Char > & chars , <nl> bool convert = false ) <nl> - : StringTableKey ( hash , chars . length ( ) ) , <nl> + : StringTableKey ( raw_hash_field , chars . length ( ) ) , <nl> chars_ ( chars ) , <nl> convert_ ( convert ) { } <nl> <nl> class SequentialStringKey final : public StringTableKey { <nl> Handle < String > AsHandle ( Isolate * isolate ) { <nl> if ( sizeof ( Char ) = = 1 ) { <nl> return isolate - > factory ( ) - > NewOneByteInternalizedString ( <nl> - Vector < const uint8_t > : : cast ( chars_ ) , hash_field ( ) ) ; <nl> + Vector < const uint8_t > : : cast ( chars_ ) , raw_hash_field ( ) ) ; <nl> } <nl> return isolate - > factory ( ) - > NewTwoByteInternalizedString ( <nl> - Vector < const uint16_t > : : cast ( chars_ ) , hash_field ( ) ) ; <nl> + Vector < const uint16_t > : : cast ( chars_ ) , raw_hash_field ( ) ) ; <nl> } <nl> <nl> Handle < String > AsHandle ( LocalIsolate * isolate ) { <nl> if ( sizeof ( Char ) = = 1 ) { <nl> return isolate - > factory ( ) - > NewOneByteInternalizedString ( <nl> - Vector < const uint8_t > : : cast ( chars_ ) , hash_field ( ) ) ; <nl> + Vector < const uint8_t > : : cast ( chars_ ) , raw_hash_field ( ) ) ; <nl> } <nl> return isolate - > factory ( ) - > NewTwoByteInternalizedString ( <nl> - Vector < const uint16_t > : : cast ( chars_ ) , hash_field ( ) ) ; <nl> + Vector < const uint16_t > : : cast ( chars_ ) , raw_hash_field ( ) ) ; <nl> } <nl> <nl> private : <nl> class SeqSubStringKey final : public StringTableKey { <nl> convert_ ( convert ) { <nl> / / We have to set the hash later . <nl> DisallowHeapAllocation no_gc ; <nl> - uint32_t hash = StringHasher : : HashSequentialString ( <nl> + uint32_t raw_hash_field = StringHasher : : HashSequentialString ( <nl> string - > GetChars ( no_gc ) + from , len , HashSeed ( isolate ) ) ; <nl> - set_hash_field ( hash ) ; <nl> + set_raw_hash_field ( raw_hash_field ) ; <nl> <nl> DCHECK_LE ( 0 , length ( ) ) ; <nl> DCHECK_LE ( from_ + length ( ) , string_ - > length ( ) ) ; <nl> class SeqSubStringKey final : public StringTableKey { <nl> if ( sizeof ( Char ) = = 1 | | ( sizeof ( Char ) = = 2 & & convert_ ) ) { <nl> Handle < SeqOneByteString > result = <nl> isolate - > factory ( ) - > AllocateRawOneByteInternalizedString ( <nl> - length ( ) , hash_field ( ) ) ; <nl> + length ( ) , raw_hash_field ( ) ) ; <nl> DisallowHeapAllocation no_gc ; <nl> CopyChars ( result - > GetChars ( no_gc ) , string_ - > GetChars ( no_gc ) + from_ , <nl> length ( ) ) ; <nl> return result ; <nl> } <nl> Handle < SeqTwoByteString > result = <nl> - isolate - > factory ( ) - > AllocateRawTwoByteInternalizedString ( length ( ) , <nl> - hash_field ( ) ) ; <nl> + isolate - > factory ( ) - > AllocateRawTwoByteInternalizedString ( <nl> + length ( ) , raw_hash_field ( ) ) ; <nl> DisallowHeapAllocation no_gc ; <nl> CopyChars ( result - > GetChars ( no_gc ) , string_ - > GetChars ( no_gc ) + from_ , <nl> length ( ) ) ; <nl> void StringCharacterStream : : VisitTwoByteString ( const uint16_t * chars , <nl> <nl> bool String : : AsArrayIndex ( uint32_t * index ) { <nl> DisallowHeapAllocation no_gc ; <nl> - uint32_t field = hash_field ( ) ; <nl> + uint32_t field = raw_hash_field ( ) ; <nl> if ( ContainsCachedArrayIndex ( field ) ) { <nl> * index = ArrayIndexValueBits : : decode ( field ) ; <nl> return true ; <nl> bool String : : AsArrayIndex ( uint32_t * index ) { <nl> } <nl> <nl> bool String : : AsIntegerIndex ( size_t * index ) { <nl> - uint32_t field = hash_field ( ) ; <nl> + uint32_t field = raw_hash_field ( ) ; <nl> if ( ContainsCachedArrayIndex ( field ) ) { <nl> * index = ArrayIndexValueBits : : decode ( field ) ; <nl> return true ; <nl> mmm a / src / objects / string - table - inl . h <nl> ppp b / src / objects / string - table - inl . h <nl> <nl> namespace v8 { <nl> namespace internal { <nl> <nl> - StringTableKey : : StringTableKey ( uint32_t hash_field , int length ) <nl> - : hash_field_ ( hash_field ) , length_ ( length ) { } <nl> + StringTableKey : : StringTableKey ( uint32_t raw_hash_field , int length ) <nl> + : raw_hash_field_ ( raw_hash_field ) , length_ ( length ) { } <nl> <nl> - void StringTableKey : : set_hash_field ( uint32_t hash_field ) { <nl> - hash_field_ = hash_field ; <nl> + void StringTableKey : : set_raw_hash_field ( uint32_t raw_hash_field ) { <nl> + raw_hash_field_ = raw_hash_field ; <nl> } <nl> <nl> uint32_t StringTableKey : : hash ( ) const { <nl> - return hash_field_ > > Name : : kHashShift ; <nl> + return raw_hash_field_ > > Name : : kHashShift ; <nl> } <nl> <nl> } / / namespace internal <nl> mmm a / src / objects / string - table . cc <nl> ppp b / src / objects / string - table . cc <nl> int ComputeStringTableCapacityWithShrink ( int current_capacity , <nl> <nl> template < typename StringTableKey > <nl> bool KeyIsMatch ( StringTableKey * key , String string ) { <nl> - if ( string . hash_field ( ) ! = key - > hash_field ( ) ) return false ; <nl> + if ( string . hash ( ) ! = key - > hash ( ) ) return false ; <nl> if ( string . length ( ) ! = key - > length ( ) ) return false ; <nl> return key - > IsMatch ( string ) ; <nl> } <nl> class InternalizedStringKey final : public StringTableKey { <nl> DCHECK ( string - > IsFlat ( ) ) ; <nl> / / Make sure hash_field is computed . <nl> string - > Hash ( ) ; <nl> - set_hash_field ( string - > hash_field ( ) ) ; <nl> + set_raw_hash_field ( string - > raw_hash_field ( ) ) ; <nl> } <nl> <nl> bool IsMatch ( String string ) override { return string_ - > SlowEquals ( string ) ; } <nl> class InternalizedStringKey final : public StringTableKey { <nl> } <nl> / / Otherwise allocate a new internalized string . <nl> return isolate - > factory ( ) - > NewInternalizedStringImpl ( <nl> - string_ , string_ - > length ( ) , string_ - > hash_field ( ) ) ; <nl> + string_ , string_ - > length ( ) , string_ - > raw_hash_field ( ) ) ; <nl> } <nl> <nl> private : <nl> Address StringTable : : Data : : TryStringToIndexOrLookupExisting ( Isolate * isolate , <nl> SequentialStringKey < Char > key ( Vector < const Char > ( chars , length ) , seed ) ; <nl> <nl> / / String could be an array index . <nl> - uint32_t hash_field = key . hash_field ( ) ; <nl> + uint32_t raw_hash_field = key . raw_hash_field ( ) ; <nl> <nl> - if ( Name : : ContainsCachedArrayIndex ( hash_field ) ) { <nl> - return Smi : : FromInt ( String : : ArrayIndexValueBits : : decode ( hash_field ) ) . ptr ( ) ; <nl> + if ( Name : : ContainsCachedArrayIndex ( raw_hash_field ) ) { <nl> + return Smi : : FromInt ( String : : ArrayIndexValueBits : : decode ( raw_hash_field ) ) <nl> + . ptr ( ) ; <nl> } <nl> <nl> - if ( ( hash_field & Name : : kIsNotIntegerIndexMask ) = = 0 ) { <nl> + if ( ( raw_hash_field & Name : : kIsNotIntegerIndexMask ) = = 0 ) { <nl> / / It is an index , but it ' s not cached . <nl> return Smi : : FromInt ( ResultSentinel : : kUnsupported ) . ptr ( ) ; <nl> } <nl> mmm a / src / objects / string - table . h <nl> ppp b / src / objects / string - table . h <nl> namespace internal { <nl> class StringTableKey { <nl> public : <nl> virtual ~ StringTableKey ( ) = default ; <nl> - inline StringTableKey ( uint32_t hash_field , int length ) ; <nl> + inline StringTableKey ( uint32_t raw_hash_field , int length ) ; <nl> <nl> / / The individual keys will have their own AsHandle , we shouldn ' t call the <nl> / / base version . <nl> Handle < String > AsHandle ( Isolate * isolate ) = delete ; <nl> <nl> - uint32_t hash_field ( ) const { <nl> - DCHECK_NE ( 0 , hash_field_ ) ; <nl> - return hash_field_ ; <nl> + uint32_t raw_hash_field ( ) const { <nl> + DCHECK_NE ( 0 , raw_hash_field_ ) ; <nl> + return raw_hash_field_ ; <nl> } <nl> <nl> virtual bool IsMatch ( String string ) = 0 ; <nl> class StringTableKey { <nl> int length ( ) const { return length_ ; } <nl> <nl> protected : <nl> - inline void set_hash_field ( uint32_t hash_field ) ; <nl> + inline void set_raw_hash_field ( uint32_t raw_hash_field ) ; <nl> <nl> private : <nl> - uint32_t hash_field_ = 0 ; <nl> + uint32_t raw_hash_field_ = 0 ; <nl> int length_ ; <nl> } ; <nl> <nl> mmm a / src / objects / string . cc <nl> ppp b / src / objects / string . cc <nl> Handle < Object > String : : ToNumber ( Isolate * isolate , Handle < String > subject ) { <nl> ( len = = 1 | | data [ 0 ] ! = ' 0 ' ) ) { <nl> / / String hash is not calculated yet but all the data are present . <nl> / / Update the hash field to speed up sequential convertions . <nl> - uint32_t hash = StringHasher : : MakeArrayIndexHash ( d , len ) ; <nl> + uint32_t raw_hash_field = StringHasher : : MakeArrayIndexHash ( d , len ) ; <nl> # ifdef DEBUG <nl> subject - > Hash ( ) ; / / Force hash calculation . <nl> - DCHECK_EQ ( static_cast < int > ( subject - > hash_field ( ) ) , <nl> - static_cast < int > ( hash ) ) ; <nl> + DCHECK_EQ ( static_cast < int > ( subject - > raw_hash_field ( ) ) , <nl> + static_cast < int > ( raw_hash_field ) ) ; <nl> # endif <nl> - subject - > set_hash_field ( hash ) ; <nl> + subject - > set_raw_hash_field ( raw_hash_field ) ; <nl> } <nl> return handle ( Smi : : FromInt ( d ) , isolate ) ; <nl> } <nl> uint32_t String : : ComputeAndSetHash ( ) { <nl> if ( string . IsThinString ( ) ) { <nl> string = ThinString : : cast ( string ) . actual ( ) ; <nl> if ( length ( ) = = string . length ( ) ) { <nl> - set_hash_field ( string . hash_field ( ) ) ; <nl> - return hash_field ( ) > > kHashShift ; <nl> + set_raw_hash_field ( string . raw_hash_field ( ) ) ; <nl> + return hash ( ) ; <nl> } <nl> } <nl> - uint32_t field = string . IsOneByteRepresentation ( ) <nl> - ? HashString < uint8_t > ( string , start , length ( ) , seed ) <nl> - : HashString < uint16_t > ( string , start , length ( ) , seed ) ; <nl> - set_hash_field ( field ) ; <nl> + uint32_t raw_hash_field = <nl> + string . IsOneByteRepresentation ( ) <nl> + ? HashString < uint8_t > ( string , start , length ( ) , seed ) <nl> + : HashString < uint16_t > ( string , start , length ( ) , seed ) ; <nl> + set_raw_hash_field ( raw_hash_field ) ; <nl> <nl> / / Check the hash code is there . <nl> DCHECK ( HasHashCode ( ) ) ; <nl> - uint32_t result = field > > kHashShift ; <nl> + uint32_t result = raw_hash_field > > kHashShift ; <nl> DCHECK_NE ( result , 0 ) ; / / Ensure that the hash value of 0 is never computed . <nl> return result ; <nl> } <nl> bool String : : SlowAsArrayIndex ( uint32_t * index ) { <nl> int length = this - > length ( ) ; <nl> if ( length < = kMaxCachedArrayIndexLength ) { <nl> Hash ( ) ; / / Force computation of hash code . <nl> - uint32_t field = hash_field ( ) ; <nl> + uint32_t field = raw_hash_field ( ) ; <nl> if ( ( field & kIsNotIntegerIndexMask ) ! = 0 ) return false ; <nl> * index = ArrayIndexValueBits : : decode ( field ) ; <nl> return true ; <nl> bool String : : SlowAsIntegerIndex ( size_t * index ) { <nl> int length = this - > length ( ) ; <nl> if ( length < = kMaxCachedArrayIndexLength ) { <nl> Hash ( ) ; / / Force computation of hash code . <nl> - uint32_t field = hash_field ( ) ; <nl> + uint32_t field = raw_hash_field ( ) ; <nl> if ( ( field & kIsNotIntegerIndexMask ) ! = 0 ) return false ; <nl> * index = ArrayIndexValueBits : : decode ( field ) ; <nl> return true ; <nl> mmm a / src / objects / string . tq <nl> ppp b / src / objects / string . tq <nl> macro AllocateSeqOneByteString ( length : uint32 ) : SeqOneByteString { <nl> if ( length = = 0 ) return UnsafeCast < SeqOneByteString > ( kEmptyString ) ; <nl> return new SeqOneByteString { <nl> map : kOneByteStringMap , <nl> - hash_field : kNameEmptyHashField , <nl> + raw_hash_field : kNameEmptyHashField , <nl> length : Signed ( length ) , <nl> chars : . . . UninitializedIterator { } <nl> } ; <nl> macro AllocateSeqTwoByteString ( length : uint32 ) : String { <nl> if ( length = = 0 ) return kEmptyString ; <nl> return new SeqTwoByteString { <nl> map : kStringMap , <nl> - hash_field : kNameEmptyHashField , <nl> + raw_hash_field : kNameEmptyHashField , <nl> length : Signed ( length ) , <nl> chars : . . . UninitializedIterator { } <nl> } ; <nl> mmm a / src / profiler / strings - storage . cc <nl> ppp b / src / profiler / strings - storage . cc <nl> const char * StringsStorage : : GetConsName ( const char * prefix , Name name ) { <nl> return " " ; <nl> } <nl> <nl> + namespace { <nl> + <nl> + inline uint32_t ComputeStringHash ( const char * str , int len ) { <nl> + uint32_t raw_hash_field = <nl> + StringHasher : : HashSequentialString ( str , len , kZeroHashSeed ) ; <nl> + return raw_hash_field > > Name : : kHashShift ; <nl> + } <nl> + <nl> + } / / namespace <nl> + <nl> bool StringsStorage : : Release ( const char * str ) { <nl> int len = static_cast < int > ( strlen ( str ) ) ; <nl> - uint32_t hash = StringHasher : : HashSequentialString ( str , len , kZeroHashSeed ) ; <nl> + uint32_t hash = ComputeStringHash ( str , len ) ; <nl> base : : HashMap : : Entry * entry = names_ . Lookup ( const_cast < char * > ( str ) , hash ) ; <nl> DCHECK ( entry ) ; <nl> if ( ! entry ) { <nl> size_t StringsStorage : : GetStringCountForTesting ( ) const { <nl> } <nl> <nl> base : : HashMap : : Entry * StringsStorage : : GetEntry ( const char * str , int len ) { <nl> - uint32_t hash = StringHasher : : HashSequentialString ( str , len , kZeroHashSeed ) ; <nl> + uint32_t hash = ComputeStringHash ( str , len ) ; <nl> return names_ . LookupOrInsert ( const_cast < char * > ( str ) , hash ) ; <nl> } <nl> <nl> mmm a / src / snapshot / deserializer . cc <nl> ppp b / src / snapshot / deserializer . cc <nl> void Deserializer : : LogScriptEvents ( Script script ) { <nl> } <nl> <nl> StringTableInsertionKey : : StringTableInsertionKey ( Handle < String > string ) <nl> - : StringTableKey ( ComputeHashField ( * string ) , string - > length ( ) ) , <nl> + : StringTableKey ( ComputeRawHashField ( * string ) , string - > length ( ) ) , <nl> string_ ( string ) { <nl> DCHECK ( string - > IsInternalizedString ( ) ) ; <nl> } <nl> Handle < String > StringTableInsertionKey : : AsHandle ( Isolate * isolate ) { <nl> return string_ ; <nl> } <nl> <nl> - uint32_t StringTableInsertionKey : : ComputeHashField ( String string ) { <nl> - / / Make sure hash_field ( ) is computed . <nl> + uint32_t StringTableInsertionKey : : ComputeRawHashField ( String string ) { <nl> + / / Make sure raw_hash_field ( ) is computed . <nl> string . Hash ( ) ; <nl> - return string . hash_field ( ) ; <nl> + return string . raw_hash_field ( ) ; <nl> } <nl> <nl> void Deserializer : : PostProcessNewObject ( Handle < Map > map , Handle < HeapObject > obj , <nl> void Deserializer : : PostProcessNewObject ( Handle < Map > map , Handle < HeapObject > obj , <nl> if ( InstanceTypeChecker : : IsString ( instance_type ) ) { <nl> / / Uninitialize hash field as we need to recompute the hash . <nl> Handle < String > string = Handle < String > : : cast ( obj ) ; <nl> - string - > set_hash_field ( String : : kEmptyHashField ) ; <nl> + string - > set_raw_hash_field ( String : : kEmptyHashField ) ; <nl> / / Rehash strings before read - only space is sealed . Strings outside <nl> / / read - only space are rehashed lazily . ( e . g . when rehashing dictionaries ) <nl> if ( space = = SnapshotSpace : : kReadOnlyHeap ) { <nl> mmm a / src / snapshot / deserializer . h <nl> ppp b / src / snapshot / deserializer . h <nl> class StringTableInsertionKey final : public StringTableKey { <nl> V8_WARN_UNUSED_RESULT Handle < String > AsHandle ( LocalIsolate * isolate ) ; <nl> <nl> private : <nl> - uint32_t ComputeHashField ( String string ) ; <nl> + uint32_t ComputeRawHashField ( String string ) ; <nl> <nl> Handle < String > string_ ; <nl> DISALLOW_HEAP_ALLOCATION ( no_gc ) <nl> mmm a / src / strings / string - hasher . h <nl> ppp b / src / strings / string - hasher . h <nl> namespace internal { <nl> template < typename T > <nl> class Vector ; <nl> <nl> + / / Helper class for incrementally calculating string hashes in a form suitable <nl> + / / for storing into Name : : raw_hash_field . <nl> class V8_EXPORT_PRIVATE StringHasher final { <nl> public : <nl> StringHasher ( ) = delete ; <nl> mmm a / test / cctest / test - debug - helper . cc <nl> ppp b / test / cctest / test - debug - helper . cc <nl> TEST ( GetObjectProperties ) { <nl> CHECK ( props - > type = = std : : string ( " v8 : : internal : : SeqOneByteString " ) ) ; <nl> CHECK_EQ ( props - > num_properties , 4 ) ; <nl> CheckProp ( * props - > properties [ 0 ] , " v8 : : internal : : Map " , " map " ) ; <nl> - CheckProp ( * props - > properties [ 1 ] , " uint32_t " , " hash_field " ) ; <nl> + CheckProp ( * props - > properties [ 1 ] , " uint32_t " , " raw_hash_field " ) ; <nl> CheckProp ( * props - > properties [ 2 ] , " int32_t " , " length " , 2 ) ; <nl> CheckProp ( * props - > properties [ 3 ] , " char " , " chars " , <nl> d : : PropertyKind : : kArrayOfKnownSize , 2 ) ; <nl> TEST ( GetObjectProperties ) { <nl> } <nl> CheckProp ( * props2 - > properties [ 0 ] , " v8 : : internal : : Map " , " map " , <nl> * reinterpret_cast < i : : Tagged_t * > ( props - > properties [ 0 ] - > address ) ) ; <nl> - CheckProp ( * props2 - > properties [ 1 ] , " uint32_t " , " hash_field " , <nl> + CheckProp ( * props2 - > properties [ 1 ] , " uint32_t " , " raw_hash_field " , <nl> * reinterpret_cast < int32_t * > ( props - > properties [ 1 ] - > address ) ) ; <nl> CheckProp ( * props2 - > properties [ 2 ] , " int32_t " , " length " , 2 ) ; <nl> } <nl> TEST ( GetObjectProperties ) { <nl> CHECK_EQ ( props2 - > num_properties , 4 ) ; <nl> CheckProp ( * props2 - > properties [ 0 ] , " v8 : : internal : : Map " , " map " , <nl> * reinterpret_cast < i : : Tagged_t * > ( props - > properties [ 0 ] - > address ) ) ; <nl> - CheckProp ( * props2 - > properties [ 1 ] , " uint32_t " , " hash_field " , <nl> + CheckProp ( * props2 - > properties [ 1 ] , " uint32_t " , " raw_hash_field " , <nl> * reinterpret_cast < i : : Tagged_t * > ( props - > properties [ 1 ] - > address ) ) ; <nl> CheckProp ( * props2 - > properties [ 2 ] , " int32_t " , " length " , 2 ) ; <nl> <nl> mmm a / test / cctest / test - descriptor - array . cc <nl> ppp b / test / cctest / test - descriptor - array . cc <nl> Handle < Name > NewNameWithHash ( Isolate * isolate , const char * str , uint32_t hash , <nl> } <nl> Handle < Name > name = isolate - > factory ( ) - > NewOneByteInternalizedString ( <nl> OneByteVector ( str ) , hash_field ) ; <nl> - name - > set_hash_field ( hash_field ) ; <nl> + name - > set_raw_hash_field ( hash_field ) ; <nl> CHECK ( name - > IsUniqueName ( ) ) ; <nl> return name ; <nl> } <nl> mmm a / test / cctest / test - strings . cc <nl> ppp b / test / cctest / test - strings . cc <nl> void TestString ( i : : Isolate * isolate , const IndexData & data ) { <nl> CHECK ( s - > AsIntegerIndex ( & index ) ) ; <nl> CHECK_EQ ( data . integer_index , index ) ; <nl> s - > Hash ( ) ; <nl> - CHECK_EQ ( 0 , s - > hash_field ( ) & String : : kIsNotIntegerIndexMask ) ; <nl> + CHECK_EQ ( 0 , s - > raw_hash_field ( ) & String : : kIsNotIntegerIndexMask ) ; <nl> CHECK ( s - > HasHashCode ( ) ) ; <nl> } <nl> if ( ! s - > HasHashCode ( ) ) s - > Hash ( ) ; <nl> CHECK ( s - > HasHashCode ( ) ) ; <nl> if ( ! data . is_integer_index ) { <nl> - CHECK_NE ( 0 , s - > hash_field ( ) & String : : kIsNotIntegerIndexMask ) ; <nl> + CHECK_NE ( 0 , s - > raw_hash_field ( ) & String : : kIsNotIntegerIndexMask ) ; <nl> } <nl> } <nl> <nl> mmm a / test / fuzzer / regexp - builtins . cc <nl> ppp b / test / fuzzer / regexp - builtins . cc <nl> void CompileRunAndVerify ( FuzzerArgs * args , const std : : string & source ) { <nl> } <nl> <nl> if ( ! ResultsAreIdentical ( args ) ) { <nl> - uint32_t hash = StringHasher : : HashSequentialString ( <nl> + uint32_t raw_hash_field = StringHasher : : HashSequentialString ( <nl> args - > input_data , static_cast < int > ( args - > input_length ) , <nl> kRegExpBuiltinsFuzzerHashSeed ) ; <nl> - FATAL ( " ! ResultAreIdentical ( args ) ; RegExpBuiltinsFuzzerHash = % x " , hash ) ; <nl> + FATAL ( " ! ResultAreIdentical ( args ) ; RegExpBuiltinsFuzzerHash = % x " , <nl> + raw_hash_field ) ; <nl> } <nl> } <nl> <nl>
[ runtime ] Deconfuse Name : : Hash ( ) from Name : : hash_field ( )
v8/v8
47ddc5b18042e50de1d91240e80d0d8fb9b9b0d2
2020-11-11T12:21:07Z
mmm a / js / apps / system / aardvark / frontend / js / modules / org / arangodb / arango - collection . js <nl> ppp b / js / apps / system / aardvark / frontend / js / modules / org / arangodb / arango - collection . js <nl> ArangoCollection . prototype . remove = function ( id , overwrite , waitForSync ) { <nl> id = id . _id ; <nl> } <nl> <nl> - var policy = " " ; <nl> + var params = " " ; <nl> <nl> - if ( overwrite ) { <nl> - policy = " ? policy = last " ; <nl> + if ( typeof overwrite = = = " object " ) { <nl> + / / we assume the caller uses new signature ( id , data , options ) <nl> + if ( typeof waitForSync ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> + var options = overwrite ; <nl> + if ( options . hasOwnProperty ( " overwrite " ) & & options . overwrite ) { <nl> + params + = " ? policy = last " ; <nl> + } <nl> + if ( options . hasOwnProperty ( " waitForSync " ) ) { <nl> + waitForSync = options . waitForSync ; <nl> + } <nl> + } else { <nl> + if ( overwrite ) { <nl> + params + = " ? policy = last " ; <nl> + } <nl> } <nl> <nl> - var url = this . _documenturl ( id ) + policy ; <nl> + var url = this . _documenturl ( id ) + params ; <nl> url = this . _appendSyncParameter ( url , waitForSync ) ; <nl> <nl> if ( rev = = = null ) { <nl> ArangoCollection . prototype . replace = function ( id , data , overwrite , waitForSync ) <nl> <nl> var params = " " ; <nl> if ( typeof overwrite = = = " object " ) { <nl> + if ( typeof waitForSync ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> / / we assume the caller uses new signature ( id , data , options ) <nl> var options = overwrite ; <nl> if ( options . hasOwnProperty ( " overwrite " ) & & options . overwrite ) { <nl> ArangoCollection . prototype . update = function ( id , data , overwrite , keepNull , wai <nl> <nl> var params = " " ; <nl> if ( typeof overwrite = = = " object " ) { <nl> + if ( typeof keepNull ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> / / we assume the caller uses new signature ( id , data , options ) <nl> var options = overwrite ; <nl> if ( ! options . hasOwnProperty ( " keepNull " ) ) { <nl> mmm a / js / apps / system / aardvark / frontend / js / modules / org / arangodb / arango - database . js <nl> ppp b / js / apps / system / aardvark / frontend / js / modules / org / arangodb / arango - database . js <nl> ArangoDatabase . prototype . _remove = function ( id , overwrite , waitForSync ) { <nl> id = id . _id ; <nl> } <nl> <nl> - var policy = " " ; <nl> + var params = " " ; <nl> <nl> - if ( overwrite ) { <nl> - policy = " ? policy = last " ; <nl> + if ( typeof overwrite = = = " object " ) { <nl> + if ( typeof waitForSync ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> + / / we assume the caller uses new signature ( id , data , options ) <nl> + var options = overwrite ; <nl> + if ( options . hasOwnProperty ( " overwrite " ) & & options . overwrite ) { <nl> + params + = " ? policy = last " ; <nl> + } <nl> + if ( options . hasOwnProperty ( " waitForSync " ) ) { <nl> + waitForSync = options . waitForSync ; <nl> + } <nl> + } else { <nl> + if ( overwrite ) { <nl> + params + = " ? policy = last " ; <nl> + } <nl> } <nl> <nl> - var url = this . _documenturl ( id ) + policy ; <nl> + var url = this . _documenturl ( id ) + params ; <nl> url = this . _appendSyncParameter ( url , waitForSync ) ; <nl> <nl> if ( rev = = = null ) { <nl> ArangoDatabase . prototype . _replace = function ( id , data , overwrite , waitForSync ) <nl> var params = " " ; <nl> <nl> if ( typeof overwrite = = = " object " ) { <nl> + if ( typeof waitForSync ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> / / we assume the caller uses new signature ( id , data , options ) <nl> var options = overwrite ; <nl> if ( options . hasOwnProperty ( " overwrite " ) & & options . overwrite ) { <nl> ArangoDatabase . prototype . _update = function ( id , data , overwrite , keepNull , wait <nl> <nl> var params = " " ; <nl> if ( typeof overwrite = = = " object " ) { <nl> + if ( typeof keepNull ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> / / we assume the caller uses new signature ( id , data , options ) <nl> var options = overwrite ; <nl> if ( ! options . hasOwnProperty ( " keepNull " ) ) { <nl> mmm a / js / client / modules / org / arangodb / arango - collection . js <nl> ppp b / js / client / modules / org / arangodb / arango - collection . js <nl> ArangoCollection . prototype . remove = function ( id , overwrite , waitForSync ) { <nl> <nl> if ( typeof overwrite = = = " object " ) { <nl> / / we assume the caller uses new signature ( id , data , options ) <nl> + if ( typeof waitForSync ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> var options = overwrite ; <nl> if ( options . hasOwnProperty ( " overwrite " ) & & options . overwrite ) { <nl> params + = " ? policy = last " ; <nl> ArangoCollection . prototype . replace = function ( id , data , overwrite , waitForSync ) <nl> <nl> var params = " " ; <nl> if ( typeof overwrite = = = " object " ) { <nl> + if ( typeof waitForSync ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> / / we assume the caller uses new signature ( id , data , options ) <nl> var options = overwrite ; <nl> if ( options . hasOwnProperty ( " overwrite " ) & & options . overwrite ) { <nl> ArangoCollection . prototype . update = function ( id , data , overwrite , keepNull , wai <nl> <nl> var params = " " ; <nl> if ( typeof overwrite = = = " object " ) { <nl> + if ( typeof keepNull ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> / / we assume the caller uses new signature ( id , data , options ) <nl> var options = overwrite ; <nl> if ( ! options . hasOwnProperty ( " keepNull " ) ) { <nl> mmm a / js / client / modules / org / arangodb / arango - database . js <nl> ppp b / js / client / modules / org / arangodb / arango - database . js <nl> ArangoDatabase . prototype . _remove = function ( id , overwrite , waitForSync ) { <nl> id = id . _id ; <nl> } <nl> <nl> - var policy = " " ; <nl> + var params = " " ; <nl> <nl> - if ( overwrite ) { <nl> - policy = " ? policy = last " ; <nl> + if ( typeof overwrite = = = " object " ) { <nl> + if ( typeof waitForSync ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> + / / we assume the caller uses new signature ( id , data , options ) <nl> + var options = overwrite ; <nl> + if ( options . hasOwnProperty ( " overwrite " ) & & options . overwrite ) { <nl> + params + = " ? policy = last " ; <nl> + } <nl> + if ( options . hasOwnProperty ( " waitForSync " ) ) { <nl> + waitForSync = options . waitForSync ; <nl> + } <nl> + } else { <nl> + if ( overwrite ) { <nl> + params + = " ? policy = last " ; <nl> + } <nl> } <nl> <nl> - var url = this . _documenturl ( id ) + policy ; <nl> + var url = this . _documenturl ( id ) + params ; <nl> url = this . _appendSyncParameter ( url , waitForSync ) ; <nl> <nl> if ( rev = = = null ) { <nl> ArangoDatabase . prototype . _replace = function ( id , data , overwrite , waitForSync ) <nl> var params = " " ; <nl> <nl> if ( typeof overwrite = = = " object " ) { <nl> + if ( typeof waitForSync ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> / / we assume the caller uses new signature ( id , data , options ) <nl> var options = overwrite ; <nl> if ( options . hasOwnProperty ( " overwrite " ) & & options . overwrite ) { <nl> ArangoDatabase . prototype . _update = function ( id , data , overwrite , keepNull , wait <nl> <nl> var params = " " ; <nl> if ( typeof overwrite = = = " object " ) { <nl> + if ( typeof keepNull ! = = " undefined " ) { <nl> + throw " too many arguments " ; <nl> + } <nl> / / we assume the caller uses new signature ( id , data , options ) <nl> var options = overwrite ; <nl> if ( ! options . hasOwnProperty ( " keepNull " ) ) { <nl>
strong examination of function parameters
arangodb/arangodb
9774991e31a85209ebd4cecdd9ad7a3be9dc63e8
2014-05-22T13:41:21Z
mmm a / stdlib / core / Dictionary . swift <nl> ppp b / stdlib / core / Dictionary . swift <nl> func = = ( lhs : _CocoaDictionaryIndex , rhs : _CocoaDictionaryIndex ) - > Bool { <nl> return lhs . nextKeyIndex = = rhs . nextKeyIndex <nl> } <nl> <nl> + enum _DictionaryIndexRepresentation < KeyType : Hashable , ValueType > { <nl> + typealias _Index = DictionaryIndex < KeyType , ValueType > <nl> + typealias _NativeIndex = _Index . _NativeIndex <nl> + typealias _CocoaIndex = _Index . _CocoaIndex <nl> + <nl> + case _Native ( _NativeIndex ) <nl> + case _Cocoa ( _CocoaIndex ) <nl> + } <nl> + <nl> @ public <nl> - enum DictionaryIndex < KeyType : Hashable , ValueType > : BidirectionalIndex { <nl> + struct DictionaryIndex < KeyType : Hashable , ValueType > : BidirectionalIndex { <nl> / / Index for native storage is efficient . Index for bridged NSDictionary is <nl> / / not , because neither NSEnumerator nor fast enumeration support moving <nl> / / backwards . Even if they did , there is another issue : NSEnumerator does <nl> enum DictionaryIndex < KeyType : Hashable , ValueType > : BidirectionalIndex { <nl> <nl> typealias _NativeIndex = _NativeDictionaryIndex < KeyType , ValueType > <nl> typealias _CocoaIndex = _CocoaDictionaryIndex <nl> - case _Native ( _NativeIndex ) <nl> - case _Cocoa ( _CocoaIndex ) <nl> + <nl> + var value : _DictionaryIndexRepresentation < KeyType , ValueType > <nl> + <nl> + static func _Native ( index : _NativeIndex ) - > DictionaryIndex { <nl> + return DictionaryIndex ( value : . _Native ( index ) ) <nl> + } <nl> + static func _Cocoa ( index : _CocoaIndex ) - > DictionaryIndex { <nl> + return DictionaryIndex ( value : . _Cocoa ( index ) ) <nl> + } <nl> <nl> @ transparent <nl> var _guaranteedNative : Bool { <nl> enum DictionaryIndex < KeyType : Hashable , ValueType > : BidirectionalIndex { <nl> <nl> @ transparent <nl> var _nativeIndex : _NativeIndex { <nl> - switch self { <nl> + switch value { <nl> case . _Native ( let nativeIndex ) : <nl> return nativeIndex <nl> case . _Cocoa : <nl> enum DictionaryIndex < KeyType : Hashable , ValueType > : BidirectionalIndex { <nl> <nl> @ transparent <nl> var _cocoaIndex : _CocoaIndex { <nl> - switch self { <nl> + switch value { <nl> case . _Native : <nl> _fatalError ( " internal error : does not contain a Cocoa index " ) <nl> case . _Cocoa ( let cocoaIndex ) : <nl> enum DictionaryIndex < KeyType : Hashable , ValueType > : BidirectionalIndex { <nl> return . _Native ( _nativeIndex . predecessor ( ) ) <nl> } <nl> <nl> - switch self { <nl> + switch value { <nl> case . _Native ( let nativeIndex ) : <nl> return . _Native ( nativeIndex . predecessor ( ) ) <nl> case . _Cocoa ( let cocoaIndex ) : <nl> enum DictionaryIndex < KeyType : Hashable , ValueType > : BidirectionalIndex { <nl> return . _Native ( _nativeIndex . successor ( ) ) <nl> } <nl> <nl> - switch self { <nl> + switch value { <nl> case . _Native ( let nativeIndex ) : <nl> return . _Native ( nativeIndex . successor ( ) ) <nl> case . _Cocoa ( let cocoaIndex ) : <nl> enum DictionaryIndex < KeyType : Hashable , ValueType > : BidirectionalIndex { <nl> return lhs . _nativeIndex = = rhs . _nativeIndex <nl> } <nl> <nl> - switch ( lhs , rhs ) { <nl> + switch ( lhs . value , rhs . value ) { <nl> case ( . _Native ( let lhsNative ) , . _Native ( let rhsNative ) ) : <nl> return lhsNative = = rhsNative <nl> case ( . _Cocoa ( let lhsCocoa ) , . _Cocoa ( let rhsCocoa ) ) : <nl> class _CocoaDictionaryGenerator : Generator { <nl> } <nl> } <nl> <nl> - @ public enum DictionaryGenerator < KeyType : Hashable , ValueType > : Generator { <nl> + enum _DictionaryGeneratorRepresentation < KeyType : Hashable , ValueType > { <nl> + typealias _Generator = DictionaryGenerator < KeyType , ValueType > <nl> + typealias _NativeIndex = _Generator . _NativeIndex <nl> + case _Native ( start : _NativeIndex , end : _NativeIndex ) <nl> + case _Cocoa ( _CocoaDictionaryGenerator ) <nl> + } <nl> + <nl> + @ public <nl> + struct DictionaryGenerator < KeyType : Hashable , ValueType > : Generator { <nl> / / Dictionary has a separate Generator and Index because of efficiency <nl> / / and implementability reasons . <nl> / / <nl> class _CocoaDictionaryGenerator : Generator { <nl> <nl> typealias _NativeIndex = _NativeDictionaryIndex < KeyType , ValueType > <nl> <nl> - case _Native ( start : _NativeIndex , end : _NativeIndex ) <nl> - case _Cocoa ( _CocoaDictionaryGenerator ) <nl> + var state : _DictionaryGeneratorRepresentation < KeyType , ValueType > <nl> + <nl> + static func _Native ( <nl> + # start : _NativeIndex , end : _NativeIndex <nl> + ) - > DictionaryGenerator { <nl> + return DictionaryGenerator ( state : . _Native ( start : start , end : end ) ) <nl> + } <nl> + static func _Cocoa ( <nl> + generator : _CocoaDictionaryGenerator <nl> + ) - > DictionaryGenerator { <nl> + return DictionaryGenerator ( state : . _Cocoa ( generator ) ) <nl> + } <nl> <nl> @ transparent <nl> var _guaranteedNative : Bool { <nl> class _CocoaDictionaryGenerator : Generator { <nl> } <nl> <nl> mutating func _nativeNext ( ) - > ( KeyType , ValueType ) ? { <nl> - switch self { <nl> + switch state { <nl> case . _Native ( var startIndex , var endIndex ) : <nl> if startIndex = = endIndex { <nl> return . None <nl> } <nl> let result = startIndex . nativeStorage . assertingGet ( startIndex ) <nl> - self = . _Native ( start : startIndex . successor ( ) , end : endIndex ) <nl> + state = . _Native ( start : startIndex . successor ( ) , end : endIndex ) <nl> return result <nl> case . _Cocoa : <nl> - _fatalError ( " internal error : not baked by NSDictionary " ) <nl> + _fatalError ( " internal error : not backed by NSDictionary " ) <nl> } <nl> } <nl> <nl> class _CocoaDictionaryGenerator : Generator { <nl> return _nativeNext ( ) <nl> } <nl> <nl> - switch self { <nl> + switch state { <nl> case . _Native ( var startIndex , var endIndex ) : <nl> return _nativeNext ( ) <nl> case . _Cocoa ( var cocoaGenerator ) : <nl>
Hide the representations of DictionaryIndex and DictionaryGenerator .
apple/swift
2ebcd5d831bf3af01d95c5b6fbb761390a9f6233
2014-07-07T18:39:33Z
mmm a / tensorflow / workspace . bzl <nl> ppp b / tensorflow / workspace . bzl <nl> def tf_workspace ( path_prefix = " " , tf_repo_name = " " ) : <nl> tf_http_archive ( <nl> name = " llvm " , <nl> urls = [ <nl> - " https : / / mirror . bazel . build / github . com / llvm - mirror / llvm / archive / 197b6c81959a17be37035d4fe71b382023bff2f0 . tar . gz " , <nl> - " https : / / github . com / llvm - mirror / llvm / archive / 197b6c81959a17be37035d4fe71b382023bff2f0 . tar . gz " , <nl> + " https : / / mirror . bazel . build / github . com / llvm - mirror / llvm / archive / 4f23838f56163df5291503f18c84a579961c313f . tar . gz " , <nl> + " https : / / github . com / llvm - mirror / llvm / archive / 4f23838f56163df5291503f18c84a579961c313f . tar . gz " , <nl> ] , <nl> - sha256 = " e77a8715fbd5d3c049bc7707da236152faab50ee2b7cec5234a0737b72ddb52a " , <nl> - strip_prefix = " llvm - 197b6c81959a17be37035d4fe71b382023bff2f0 " , <nl> + sha256 = " ed4516ad56365d0c94b01db4e0331cc895848c5a90a5c8f3b38c96bc0ed872eb " , <nl> + strip_prefix = " llvm - 4f23838f56163df5291503f18c84a579961c313f " , <nl> build_file = str ( Label ( " / / third_party / llvm : llvm . BUILD " ) ) , <nl> ) <nl> <nl>
[ TF : XLA ] Bump open source llvm revision to r327373
tensorflow/tensorflow
b71c0590d1ee8dc4f13a222ac52fdfc1eff1fa0d
2018-03-13T19:08:19Z
mmm a / ports / openimageio / CONTROL <nl> ppp b / ports / openimageio / CONTROL <nl> <nl> Source : openimageio <nl> - Version : 2019 - 08 - 08 - 4 <nl> + Version : 2 . 1 . 9 . 0 <nl> Homepage : https : / / github . com / OpenImageIO / oiio <nl> Description : A library for reading and writing images , and a bunch of related classes , utilities , and application <nl> Build - Depends : libjpeg - turbo , tiff , libpng , openexr , boost - thread , boost - smart - ptr , boost - foreach , boost - regex , boost - type - traits , boost - static - assert , boost - unordered , boost - config , boost - algorithm , boost - filesystem , boost - system , boost - thread , boost - asio , boost - random , robin - map , boost - stacktrace <nl> Description : Enable RAW image files support <nl> <nl> Feature : opencolorio <nl> Build - Depends : opencolorio <nl> - Description : Enable opencolorio support for openimageio <nl> \ No newline at end of file <nl> + Description : Enable opencolorio support for openimageio <nl> + <nl> + Feature : ffmpeg <nl> + Build - Depends : ffmpeg [ avresample ] <nl> + Description : Enable ffmpeg support for openimageio <nl> + <nl> + Feature : field3d <nl> + Build - Depends : field3d <nl> + Description : Enable field3D support for openimageio <nl> + <nl> + Feature : freetype <nl> + Build - Depends : freetype <nl> + Description : Enable freetype support for openimageio <nl> + <nl> + Feature : opencv <nl> + Build - Depends : opencv <nl> + Description : Enable opencv support for openimageio <nl> + <nl> + Feature : gif <nl> + Build - Depends : giflib <nl> + Description : Enable giflib support for openimageio <nl> + <nl> + Feature : openjpeg <nl> + Build - Depends : openjpeg <nl> + Description : Enable openjpeg support for openimageio <nl> + <nl> + Feature : webp <nl> + Build - Depends : libwebp <nl> + Description : Enable libwebp support for openimageio <nl> + <nl> + Feature : pybind11 <nl> + Build - Depends : pybind11 <nl> + Description : Enable Python bindings support for openimageio <nl> + <nl> + Feature : tools <nl> + Description : Build openimageio tools <nl> \ No newline at end of file <nl> new file mode 100644 <nl> index 00000000000 . . f61afccbd8b <nl> mmm / dev / null <nl> ppp b / ports / openimageio / fix - config - cmake . patch <nl> <nl> pppmmm a / src / cmake / Config . cmake . in <nl> ppp + b / src / cmake / Config . cmake . in <nl> + include ( CMakeFindDependencyMacro ) <nl> + # e . g . if switching to Boost : : Boost instead of using $ { Boost_LIBRARY_DIRS } the add : <nl> + # find_dependency ( Boost @ Boost_VERSION @ ) <nl> + <nl> + - include ( " $ { CMAKE_CURRENT_LIST_DIR } / @ targets_export_name @ . cmake " ) <nl> + + include ( " $ { CMAKE_CURRENT_LIST_DIR } / OpenImageIOTargets . cmake " ) <nl> + check_required_components ( " @ PROJECT_NAME @ " ) <nl> + \ No newline at end of file <nl> new file mode 100644 <nl> index 00000000000 . . 3dc3a16d01d <nl> mmm / dev / null <nl> ppp b / ports / openimageio / fix - dependency . patch <nl> <nl> pppmmm a / src / cmake / externalpackages . cmake <nl> ppp + b / src / cmake / externalpackages . cmake <nl> + checked_find_package ( PNG REQUIRED ) <nl> + checked_find_package ( TIFF 3 . 0 REQUIRED ) <nl> + <nl> + # IlmBase & OpenEXR <nl> + + find_package ( Threads ) <nl> + + if ( CMAKE_USE_PTHREADS_INIT ) <nl> + + set ( ILMBASE_PTHREADS $ { CMAKE_THREAD_LIBS_INIT } ) <nl> + + endif ( ) <nl> + checked_find_package ( OpenEXR 2 . 0 REQUIRED ) <nl> + # We use Imath so commonly , may as well include it everywhere . <nl> + - include_directories ( " $ { OPENEXR_INCLUDES } " " $ { ILMBASE_INCLUDES } " <nl> + - " $ { ILMBASE_INCLUDES } / OpenEXR " ) <nl> + + set ( ILMBASE_LIBRARIES $ { OPENEXR_IMATH_LIBRARY } $ { OPENEXR_IEX_LIBRARY } $ { OPENEXR_HALF_LIBRARY } $ { OPENEXR_ILMTHREAD_LIBRARY } $ { ILMBASE_PTHREADS } CACHE STRING " The libraries needed to use IlmBase " ) <nl> + + set ( OPENEXR_LIBRARIES $ { OPENEXR_ILMIMF_LIBRARY } $ { ILMBASE_LIBRARIES } CACHE STRING " The libraries needed to use OpenEXR " ) <nl> + + set ( ILMBASE_INCLUDE_DIR $ { OPENEXR_INCLUDE_DIR } ) <nl> + + set ( ILMBASE_FOUND TRUE ) <nl> + + include_directories ( " $ { OPENEXR_INCLUDE_DIR } " ) <nl> + if ( CMAKE_COMPILER_IS_CLANG AND OPENEXR_VERSION VERSION_LESS 2 . 3 ) <nl> + # clang C + + > = 11 doesn ' t like ' register ' keyword in old exr headers <nl> + add_compile_options ( - Wno - deprecated - register ) <nl> + checked_find_package ( HDF5 <nl> + ISDEPOF Field3D ) <nl> + checked_find_package ( OpenColorIO <nl> + DEFINITIONS - DUSE_OCIO = 1 - DUSE_OPENCOLORIO = 1 ) <nl> + - checked_find_package ( OpenCV <nl> + + checked_find_package ( OpenCV CONFIG <nl> + DEFINITIONS - DUSE_OPENCV = 1 ) <nl> + <nl> + # Intel TBB <nl> + checked_find_package ( TBB 2017 <nl> + ISDEPOF OpenVDB ) <nl> + <nl> + checked_find_package ( DCMTK 3 . 6 . 1 ) # For DICOM images <nl> + - checked_find_package ( FFmpeg 2 . 6 ) <nl> + + checked_find_package ( FFMPEG ) <nl> + checked_find_package ( Field3D <nl> + DEPS HDF5 <nl> + DEFINITIONS - DUSE_FIELD3D = 1 ) <nl> + checked_find_package ( GIF 4 ) <nl> + checked_find_package ( Libheif 1 . 3 ) # For HEIF / HEIC format <nl> + checked_find_package ( LibRaw ) <nl> + - checked_find_package ( OpenJpeg ) <nl> + + checked_find_package ( OpenJPEG CONFIG ) <nl> + checked_find_package ( OpenVDB 5 . 0 <nl> + DEPS TBB <nl> + DEFINITIONS - DUSE_OPENVDB = 1 ) <nl> + - checked_find_package ( PTex ) <nl> + - checked_find_package ( Webp ) <nl> + + checked_find_package ( ptex CONFIG ) <nl> + + set ( PTEX_FOUND $ { ptex_FOUND } ) <nl> + + set ( PTEX_LIBRARIES Ptex : : Ptex ) <nl> + + checked_find_package ( Webp CONFIG ) <nl> + + set ( WEBP_FOUND $ { Webp_FOUND } ) <nl> + + set ( WEBP_LIBRARY WebP : : webp WebP : : webpdemux WebP : : webpdecoder ) <nl> + <nl> + option ( USE_R3DSDK " Enable R3DSDK ( RED camera ) support " OFF ) <nl> + checked_find_package ( R3DSDK ) # RED camera <nl> + if ( OPENGL_FOUND ) <nl> + list ( APPEND qt5_modules OpenGL ) <nl> + endif ( ) <nl> + option ( USE_QT " Use Qt if found " ON ) <nl> + + if ( USE_QT ) <nl> + checked_find_package ( Qt5 COMPONENTS $ { qt5_modules } ) <nl> + + endif ( ) <nl> + if ( USE_QT AND NOT Qt5_FOUND AND APPLE ) <nl> + message ( STATUS " If you think you installed qt5 with Homebrew and it still doesn ' t work , " ) <nl> + message ( STATUS " try : export PATH = / usr / local / opt / qt5 / bin : $ PATH " ) <nl> pppmmm a / src / jpeg2000 . imageio / CMakeLists . txt <nl> ppp + b / src / jpeg2000 . imageio / CMakeLists . txt <nl> + <nl> + # https : / / github . com / OpenImageIO / oiio / blob / master / LICENSE . md <nl> + <nl> + if ( OPENJPEG_FOUND ) <nl> + - if ( $ { OPENJPEG_VERSION } VERSION_LESS 2 . 0 ) <nl> + + if ( 0 ) <nl> + # Old OpenJpeg 1 . 5 . Remove this eventually . <nl> + # <nl> + # For reasons I don ' t understand , OpenJPEG 1 . 5 fails imageinout_test <nl> pppmmm a / src / raw . imageio / CMakeLists . txt <nl> ppp + b / src / raw . imageio / CMakeLists . txt <nl> + <nl> + if ( LIBRAW_FOUND ) <nl> + add_oiio_plugin ( rawinput . cpp <nl> + INCLUDE_DIRS $ { LibRaw_INCLUDE_DIR } <nl> + - LINK_LIBRARIES $ { LibRaw_r_LIBRARIES } <nl> + + LINK_LIBRARIES $ { LibRaw_LIBRARIES } <nl> + DEFINITIONS " - DUSE_LIBRAW = 1 " ) <nl> + else ( ) <nl> + message ( WARNING " Raw plugin will not be built " ) <nl> new file mode 100644 <nl> index 00000000000 . . b7bf3753bd1 <nl> mmm / dev / null <nl> ppp b / ports / openimageio / fix - tools - path . patch <nl> <nl> pppmmm a / src / cmake / oiio_macros . cmake <nl> ppp + b / src / cmake / oiio_macros . cmake <nl> + macro ( fancy_add_executable ) <nl> + target_link_libraries ( $ { _target_NAME } PRIVATE $ { _target_LINK_LIBRARIES } ) <nl> + endif ( ) <nl> + set_target_properties ( $ { _target_NAME } PROPERTIES FOLDER " Tools " ) <nl> + - install_targets ( $ { _target_NAME } ) <nl> + + install ( TARGETS $ { _target_NAME } RUNTIME DESTINATION tools / openimageio ) <nl> + else ( ) <nl> + message ( STATUS " $ { ColorRed } Disabling $ { _target_NAME } $ { ColorReset } " ) <nl> + endif ( ) <nl> deleted file mode 100644 <nl> index 707530247bf . . 00000000000 <nl> mmm a / ports / openimageio / fix_libraw . patch <nl> ppp / dev / null <nl> <nl> mmmmmm a / src / cmake / externalpackages . cmake <nl> - ppp b / src / cmake / externalpackages . cmake <nl> - if ( USE_LIBRAW ) <nl> - message ( STATUS " Looking for LibRaw with $ { LIBRAW_PATH } " ) <nl> - endif ( ) <nl> - find_package ( LibRaw ) <nl> - - if ( LibRaw_r_LIBRARIES AND LibRaw_INCLUDE_DIR ) <nl> - + if ( LibRaw_LIBRARIES AND LibRaw_INCLUDE_DIR ) <nl> - set ( LIBRAW_FOUND TRUE ) <nl> - include_directories ( $ { LibRaw_INCLUDE_DIR } ) <nl> - if ( NOT LibRaw_FIND_QUIETLY ) <nl> - if ( USE_LIBRAW ) <nl> - if ( LINKSTATIC ) <nl> - find_package ( Jasper ) <nl> - find_library ( LCMS2_LIBRARIES NAMES lcms2 ) <nl> - - set ( LibRaw_r_LIBRARIES $ { LibRaw_r_LIBRARIES } $ { JASPER_LIBRARIES } $ { LCMS2_LIBRARIES } ) <nl> - + set ( LibRaw_LIBRARIES $ { LibRaw_LIBRARIES } $ { JASPER_LIBRARIES } $ { LCMS2_LIBRARIES } ) <nl> - endif ( ) <nl> - else ( ) <nl> - message ( STATUS " Not using LibRaw " ) <nl> mmmmmm a / src / raw . imageio / CMakeLists . txt <nl> - ppp b / src / raw . imageio / CMakeLists . txt <nl> - <nl> - if ( USE_LIBRAW AND LIBRAW_FOUND ) <nl> - add_oiio_plugin ( rawinput . cpp <nl> - INCLUDE_DIRS $ { LibRaw_INCLUDE_DIR } <nl> - - LINK_LIBRARIES $ { LibRaw_r_LIBRARIES } <nl> - + LINK_LIBRARIES $ { LibRaw_LIBRARIES } <nl> - DEFINITIONS " - DUSE_LIBRAW = 1 " ) <nl> - else ( ) <nl> - message ( WARNING " Raw plugin will not be built " ) <nl> new file mode 100644 <nl> index 00000000000 . . 825026dc8bf <nl> mmm / dev / null <nl> ppp b / ports / openimageio / fix_static_build . patch <nl> <nl> pppmmm a / src / cmake / compiler . cmake <nl> ppp + b / src / cmake / compiler . cmake <nl> + set ( EXTRA_DSO_LINK_ARGS " " CACHE STRING " Extra command line definitions when bu <nl> + # <nl> + option ( BUILD_SHARED_LIBS " Build shared libraries ( set to OFF to build static libs ) " ON ) <nl> + if ( NOT BUILD_SHARED_LIBS ) <nl> + - add_definitions ( - D $ { PROJECT_NAME } _STATIC_DEFINE = 1 ) <nl> + + add_definitions ( - DOIIO_STATIC_DEFINE = 1 ) <nl> + endif ( ) <nl> + <nl> + <nl> mmm a / ports / openimageio / portfile . cmake <nl> ppp b / ports / openimageio / portfile . cmake <nl> <nl> - include ( vcpkg_common_functions ) <nl> - <nl> vcpkg_from_github ( <nl> OUT_SOURCE_PATH SOURCE_PATH <nl> REPO OpenImageIO / oiio <nl> - REF ad1ab61a56c63d770e4beb335efe8b1f1a9e36cd <nl> - SHA512 48ee7862583e7adb86b56b20634c34aebf83ef0a3a14ad96182494ce6a84cb027334840a6c4c335e9342110c3a36532e3eeae22a3ed7363cd91b27cb7ca58154 <nl> + REF fdd982a9922ff508b8b22e5d024356b582572f46 # 2 . 1 . 9 . 0 <nl> + SHA512 1d076cb035b1b2cb603343465ed810ca47223211870d58f48c177d40d71a9cf82e53548b0c70127daf5dbd06f1b24772919e49e55110d914a542bcb62b99f6e8 <nl> HEAD_REF master <nl> PATCHES <nl> - fix_libraw . patch <nl> - use - webp . patch <nl> - remove_wrong_dependency . patch <nl> - use - vcpkg - find - openexr . patch <nl> + fix - dependency . patch <nl> + fix_static_build . patch <nl> + fix - tools - path . patch <nl> + fix - config - cmake . patch <nl> ) <nl> <nl> file ( REMOVE_RECURSE " $ { SOURCE_PATH } / ext " ) <nl> <nl> - file ( REMOVE " $ { SOURCE_PATH } / src / cmake / modules / FindLibRaw . cmake " ) <nl> - file ( REMOVE " $ { SOURCE_PATH } / src / cmake / modules / FindOpenEXR . cmake " ) <nl> + file ( REMOVE " $ { SOURCE_PATH } / src / cmake / modules / FindLibRaw . cmake " <nl> + " $ { SOURCE_PATH } / src / cmake / modules / FindOpenEXR . cmake " <nl> + " $ { SOURCE_PATH } / src / cmake / modules / FindOpenCV . cmake " <nl> + " $ { SOURCE_PATH } / src / cmake / modules / FindFFmpeg . cmake " <nl> + " $ { SOURCE_PATH } / src / cmake / modules / FindWebp . cmake " ) <nl> <nl> file ( MAKE_DIRECTORY " $ { SOURCE_PATH } / ext / robin - map / tsl " ) <nl> <nl> if ( VCPKG_LIBRARY_LINKAGE STREQUAL static ) <nl> - set ( BUILDSTATIC ON ) <nl> set ( LINKSTATIC ON ) <nl> else ( ) <nl> - set ( BUILDSTATIC OFF ) <nl> set ( LINKSTATIC OFF ) <nl> endif ( ) <nl> <nl> vcpkg_check_features ( OUT_FEATURE_OPTIONS FEATURE_OPTIONS <nl> - libraw USE_LIBRAW <nl> - opencolorio USE_OCIO <nl> + libraw USE_LIBRAW <nl> + opencolorio USE_OCIO <nl> + ffmpeg USE_FFMPEG <nl> + field3d USE_FIELD3D <nl> + freetype USE_FREETYPE <nl> + gif USE_GIF <nl> + opencv USE_OPENCV <nl> + openjpeg USE_OPENJPEG <nl> + webp USE_WEBP <nl> + pybind11 USE_PYTHON <nl> + tools OIIO_BUILD_TOOLS <nl> ) <nl> <nl> + vcpkg_find_acquire_program ( PYTHON3 ) <nl> + get_filename_component ( PYTHON3_DIR " $ { PYTHON3 } " DIRECTORY ) <nl> + vcpkg_add_to_path ( " $ { PYTHON3_DIR } " ) <nl> + <nl> vcpkg_configure_cmake ( <nl> SOURCE_PATH $ { SOURCE_PATH } <nl> PREFER_NINJA <nl> OPTIONS $ { FEATURE_OPTIONS } <nl> - - DOIIO_BUILD_TOOLS = OFF <nl> - DOIIO_BUILD_TESTS = OFF <nl> - DHIDE_SYMBOLS = ON <nl> - - DUSE_DICOM = OFF <nl> - - DUSE_FFMPEG = OFF <nl> - - DUSE_FIELD3D = OFF <nl> - - DUSE_FREETYPE = OFF <nl> - - DUSE_GIF = OFF <nl> + - DUSE_DCMTK = OFF <nl> - DUSE_NUKE = OFF <nl> - - DUSE_OPENCV = OFF <nl> - - DUSE_OPENJPEG = OFF <nl> - - DUSE_OPENSSL = OFF <nl> - - DUSE_PTEX = OFF <nl> - - DUSE_PYTHON = OFF <nl> - DUSE_QT = OFF <nl> - - DUSE_WEBP = OFF <nl> - - DBUILDSTATIC = $ { BUILDSTATIC } <nl> + - DUSE_PTEX = OFF <nl> - DLINKSTATIC = $ { LINKSTATIC } <nl> - DBUILD_MISSING_PYBIND11 = OFF <nl> - DBUILD_MISSING_DEPS = OFF <nl> - - DCMAKE_DISABLE_FIND_PACKAGE_Git = ON <nl> - DVERBOSE = ON <nl> - OPTIONS_DEBUG <nl> - - DOPENEXR_CUSTOM_LIB_DIR = $ { CURRENT_INSTALLED_DIR } / debug / lib <nl> ) <nl> <nl> vcpkg_install_cmake ( ) <nl> <nl> vcpkg_copy_pdbs ( ) <nl> <nl> + vcpkg_fixup_cmake_targets ( CONFIG_PATH lib / cmake / OpenImageIO ) <nl> + <nl> + if ( " tools " IN_LIST FEATURES ) <nl> + vcpkg_copy_tool_dependencies ( $ { CURRENT_PACKAGES_DIR } / tools / openimageio ) <nl> + endif ( ) <nl> + <nl> # Clean <nl> - file ( REMOVE_RECURSE $ { CURRENT_PACKAGES_DIR } / doc ) <nl> - file ( REMOVE_RECURSE $ { CURRENT_PACKAGES_DIR } / debug / doc ) <nl> - file ( REMOVE_RECURSE $ { CURRENT_PACKAGES_DIR } / debug / include ) <nl> - file ( REMOVE_RECURSE $ { CURRENT_PACKAGES_DIR } / debug / share ) <nl> + file ( REMOVE_RECURSE $ { CURRENT_PACKAGES_DIR } / doc <nl> + $ { CURRENT_PACKAGES_DIR } / debug / doc <nl> + $ { CURRENT_PACKAGES_DIR } / debug / include <nl> + $ { CURRENT_PACKAGES_DIR } / debug / share ) <nl> <nl> file ( COPY $ { SOURCE_PATH } / src / cmake / modules / FindOpenImageIO . cmake DESTINATION $ { CURRENT_PACKAGES_DIR } / share / $ { PORT } ) <nl> file ( COPY $ { CMAKE_CURRENT_LIST_DIR } / vcpkg - cmake - wrapper . cmake DESTINATION $ { CURRENT_PACKAGES_DIR } / share / $ { PORT } ) <nl> <nl> # Handle copyright <nl> - file ( COPY $ { SOURCE_PATH } / LICENSE . md DESTINATION $ { CURRENT_PACKAGES_DIR } / share / openimageio ) <nl> - file ( RENAME $ { CURRENT_PACKAGES_DIR } / share / openimageio / LICENSE . md $ { CURRENT_PACKAGES_DIR } / share / openimageio / copyright ) <nl> + file ( INSTALL $ { SOURCE_PATH } / LICENSE . md DESTINATION $ { CURRENT_PACKAGES_DIR } / share / $ { PORT } RENAME copyright ) <nl> deleted file mode 100644 <nl> index 5338c6563c9 . . 00000000000 <nl> mmm a / ports / openimageio / remove_wrong_dependency . patch <nl> ppp / dev / null <nl> <nl> - diff - - git a / src / libOpenImageIO / CMakeLists . txt b / src / libOpenImageIO / CMakeLists . txt <nl> - index 5449675 . . cdd5235 100644 <nl> mmm - a / src / libOpenImageIO / CMakeLists . txt <nl> - ppp b / src / libOpenImageIO / CMakeLists . txt <nl> - elseif ( MINGW ) <nl> - target_link_libraries ( OpenImageIO psapi ws2_32 ) <nl> - endif ( ) <nl> - <nl> - - if ( VISIBILITY_MAP_FILE ) <nl> - - add_dependencies ( OpenImageIO " $ { VISIBILITY_MAP_FILE } " ) <nl> - - endif ( ) <nl> - - <nl> - if ( USE_EXTERNAL_PUGIXML ) <nl> - target_link_libraries ( OpenImageIO $ { PUGIXML_LIBRARIES } ) <nl> - endif ( ) <nl> deleted file mode 100644 <nl> index bacc4f686ea . . 00000000000 <nl> mmm a / ports / openimageio / use - vcpkg - find - openexr . patch <nl> ppp / dev / null <nl> <nl> mmmmmm a / src / cmake / externalpackages . cmake <nl> - ppp b / src / cmake / externalpackages . cmake <nl> - find_package ( PNG REQUIRED ) <nl> - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> - # IlmBase & OpenEXR setup <nl> - <nl> - + find_package ( Threads ) <nl> - + if ( CMAKE_USE_PTHREADS_INIT ) <nl> - + set ( ILMBASE_PTHREADS $ { CMAKE_THREAD_LIBS_INIT } ) <nl> - + endif ( ) <nl> - + <nl> - find_package ( OpenEXR 2 . 0 REQUIRED ) <nl> - # OpenEXR 2 . 2 still has problems with importing ImathInt64 . h unqualified <nl> - # thus need for ilmbase / OpenEXR <nl> - - include_directories ( " $ { OPENEXR_INCLUDE_DIR } " <nl> - - " $ { ILMBASE_INCLUDE_DIR } " <nl> - - " $ { ILMBASE_INCLUDE_DIR } / OpenEXR " ) <nl> - + set ( ILMBASE_LIBRARIES $ { OPENEXR_IMATH_LIBRARY } $ { OPENEXR_IEX_LIBRARY } $ { OPENEXR_HALF_LIBRARY } $ { OPENEXR_ILMTHREAD_LIBRARY } $ { ILMBASE_PTHREADS } CACHE STRING " The libraries needed to use IlmBase " ) <nl> - + set ( OPENEXR_LIBRARIES $ { OPENEXR_ILMIMF_LIBRARY } $ { ILMBASE_LIBRARIES } CACHE STRING " The libraries needed to use OpenEXR " ) <nl> - + set ( ILMBASE_INCLUDE_DIR $ { OPENEXR_INCLUDE_DIR } ) <nl> - + set ( ILMBASE_FOUND TRUE ) <nl> - + include_directories ( " $ { OPENEXR_INCLUDE_DIR } " ) <nl> - if ( NOT OpenEXR_FIND_QUIETLY ) <nl> - message ( STATUS " OPENEXR_INCLUDE_DIR = $ { OPENEXR_INCLUDE_DIR } " ) <nl> - message ( STATUS " OPENEXR_LIBRARIES = $ { OPENEXR_LIBRARIES } " ) <nl> deleted file mode 100644 <nl> index ab03b170372 . . 00000000000 <nl> mmm a / ports / openimageio / use - webp . patch <nl> ppp / dev / null <nl> <nl> mmmmmm a / CMakeLists . txt <nl> - ppp b / CMakeLists . txt <nl> - option ( USE_GIF " Use GIF if found " ON ) <nl> - option ( USE_PTEX " Use PTex if found " ON ) <nl> - option ( USE_WEBP " Use WebP if found " ON ) <nl> - option ( USE_LIBRAW " Use LibRaw if found " ON ) <nl> - + option ( USE_WEBP " Use WebP if found " ON ) <nl> - set ( LIBRAW_PATH " " CACHE STRING " Custom LibRaw path " ) <nl> - option ( OIIO_THREAD_ALLOW_DCLP " OIIO threads may use DCLP for speed " ON ) <nl> - option ( USE_NUKE " Build Nuke plugins , if Nuke is found " ON ) <nl> mmmmmm a / src / cmake / externalpackages . cmake <nl> - ppp b / src / cmake / externalpackages . cmake <nl> - if ( USE_WEBP ) <nl> - if ( NOT WEBP_FIND_QUIETLY ) <nl> - message ( STATUS " WEBP_HOME = $ { WEBP_HOME } " ) <nl> - endif ( ) <nl> - + if ( USE_WEBP ) <nl> - find_path ( WEBP_INCLUDE_DIR webp / encode . h <nl> - " $ { PROJECT_SOURCE_DIR } / src / include " <nl> - " $ { WEBP_HOME } " ) <nl> - if ( USE_WEBP ) <nl> - set ( WEBP_FOUND FALSE ) <nl> - message ( STATUS " WebP library not found " ) <nl> - endif ( ) <nl> - + else ( ) <nl> - + set ( WEBP_FOUND FALSE ) <nl> - + endif ( ) <nl> - else ( ) <nl> - message ( STATUS " Not using WebP " ) <nl> - endif ( ) <nl>
[ openimageio ] Upgrade version , add features and fix build failure ( )
microsoft/vcpkg
b20c6d3b89b9fa22a19e3609e6df2fcfc20f968f
2020-02-09T06:35:45Z
mmm a / programs / copier / Internals . cpp <nl> ppp b / programs / copier / Internals . cpp <nl> <nl> # include " Internals . h " <nl> # include < Storages / MergeTree / MergeTreeData . h > <nl> + # include < Storages / extractKeyExpressionList . h > <nl> <nl> namespace DB <nl> { <nl> Names extractPrimaryKeyColumnNames ( const ASTPtr & storage_ast ) <nl> const auto sorting_key_ast = extractOrderBy ( storage_ast ) ; <nl> const auto primary_key_ast = extractPrimaryKey ( storage_ast ) ; <nl> <nl> - const auto sorting_key_expr_list = MergeTreeData : : extractKeyExpressionList ( sorting_key_ast ) ; <nl> + const auto sorting_key_expr_list = extractKeyExpressionList ( sorting_key_ast ) ; <nl> const auto primary_key_expr_list = primary_key_ast <nl> - ? MergeTreeData : : extractKeyExpressionList ( primary_key_ast ) : sorting_key_expr_list - > clone ( ) ; <nl> + ? extractKeyExpressionList ( primary_key_ast ) : sorting_key_expr_list - > clone ( ) ; <nl> <nl> / / / Maybe we have to handle VersionedCollapsing engine separately . But in our case in looks pointless . <nl> <nl> mmm a / src / DataStreams / PushingToViewsBlockOutputStream . cpp <nl> ppp b / src / DataStreams / PushingToViewsBlockOutputStream . cpp <nl> PushingToViewsBlockOutputStream : : PushingToViewsBlockOutputStream ( <nl> <nl> StoragePtr inner_table = materialized_view - > getTargetTable ( ) ; <nl> auto inner_table_id = inner_table - > getStorageID ( ) ; <nl> - query = materialized_view - > getInnerQuery ( ) ; <nl> + query = materialized_view - > getSelectQuery ( ) . inner_query ; <nl> <nl> std : : unique_ptr < ASTInsertQuery > insert = std : : make_unique < ASTInsertQuery > ( ) ; <nl> insert - > table_id = inner_table_id ; <nl> mmm a / src / DataStreams / TTLBlockInputStream . cpp <nl> ppp b / src / DataStreams / TTLBlockInputStream . cpp <nl> TTLBlockInputStream : : TTLBlockInputStream ( <nl> defaults_expression = ExpressionAnalyzer { default_expr_list , syntax_result , storage . global_context } . getActions ( true ) ; <nl> } <nl> <nl> - if ( storage . hasRowsTTL ( ) & & storage . getRowsTTL ( ) . mode = = TTLMode : : GROUP_BY ) <nl> + auto storage_rows_ttl = storage . getRowsTTL ( ) ; <nl> + if ( storage . hasRowsTTL ( ) & & storage_rows_ttl . mode = = TTLMode : : GROUP_BY ) <nl> { <nl> - current_key_value . resize ( storage . getRowsTTL ( ) . group_by_keys . size ( ) ) ; <nl> + current_key_value . resize ( storage_rows_ttl . group_by_keys . size ( ) ) ; <nl> <nl> ColumnNumbers keys ; <nl> - for ( const auto & key : storage . getRowsTTL ( ) . group_by_keys ) <nl> + for ( const auto & key : storage_rows_ttl . group_by_keys ) <nl> keys . push_back ( header . getPositionByName ( key ) ) ; <nl> - agg_key_columns . resize ( storage . getRowsTTL ( ) . group_by_keys . size ( ) ) ; <nl> + agg_key_columns . resize ( storage_rows_ttl . group_by_keys . size ( ) ) ; <nl> <nl> - AggregateDescriptions aggregates = storage . getRowsTTL ( ) . aggregate_descriptions ; <nl> + AggregateDescriptions aggregates = storage_rows_ttl . aggregate_descriptions ; <nl> for ( auto & descr : aggregates ) <nl> if ( descr . arguments . empty ( ) ) <nl> for ( const auto & name : descr . argument_names ) <nl> descr . arguments . push_back ( header . getPositionByName ( name ) ) ; <nl> - agg_aggregate_columns . resize ( storage . getRowsTTL ( ) . aggregate_descriptions . size ( ) ) ; <nl> + agg_aggregate_columns . resize ( storage_rows_ttl . aggregate_descriptions . size ( ) ) ; <nl> <nl> const Settings & settings = storage . global_context . getSettingsRef ( ) ; <nl> <nl> bool TTLBlockInputStream : : isTTLExpired ( time_t ttl ) const <nl> Block TTLBlockInputStream : : readImpl ( ) <nl> { <nl> / / / Skip all data if table ttl is expired for part <nl> - if ( storage . hasRowsTTL ( ) & & ! storage . getRowsTTL ( ) . where_expression & & <nl> - storage . getRowsTTL ( ) . mode ! = TTLMode : : GROUP_BY & & isTTLExpired ( old_ttl_infos . table_ttl . max ) ) <nl> + auto storage_rows_ttl = storage . getRowsTTL ( ) ; <nl> + if ( storage . hasRowsTTL ( ) & & ! storage_rows_ttl . where_expression & & <nl> + storage_rows_ttl . mode ! = TTLMode : : GROUP_BY & & isTTLExpired ( old_ttl_infos . table_ttl . max ) ) <nl> { <nl> rows_removed = data_part - > rows_count ; <nl> return { } ; <nl> void TTLBlockInputStream : : readSuffixImpl ( ) <nl> <nl> void TTLBlockInputStream : : removeRowsWithExpiredTableTTL ( Block & block ) <nl> { <nl> - const auto & rows_ttl = storage . getRowsTTL ( ) ; <nl> + auto rows_ttl = storage . getRowsTTL ( ) ; <nl> <nl> rows_ttl . expression - > execute ( block ) ; <nl> if ( rows_ttl . where_expression ) <nl> void TTLBlockInputStream : : removeRowsWithExpiredTableTTL ( Block & block ) <nl> const IColumn * ttl_column = <nl> block . getByName ( rows_ttl . result_column ) . column . get ( ) ; <nl> <nl> - const IColumn * where_result_column = storage . getRowsTTL ( ) . where_expression ? <nl> - block . getByName ( storage . getRowsTTL ( ) . where_result_column ) . column . get ( ) : nullptr ; <nl> + const IColumn * where_result_column = rows_ttl . where_expression ? <nl> + block . getByName ( rows_ttl . where_result_column ) . column . get ( ) : nullptr ; <nl> <nl> const auto & column_names = header . getNames ( ) ; <nl> <nl> void TTLBlockInputStream : : removeRowsWithExpiredTableTTL ( Block & block ) <nl> size_t rows_aggregated = 0 ; <nl> size_t current_key_start = 0 ; <nl> size_t rows_with_current_key = 0 ; <nl> + auto storage_rows_ttl = storage . getRowsTTL ( ) ; <nl> for ( size_t i = 0 ; i < block . rows ( ) ; + + i ) <nl> { <nl> UInt32 cur_ttl = getTimestampByIndex ( ttl_column , i ) ; <nl> void TTLBlockInputStream : : removeRowsWithExpiredTableTTL ( Block & block ) <nl> bool ttl_expired = isTTLExpired ( cur_ttl ) & & where_filter_passed ; <nl> <nl> bool same_as_current = true ; <nl> - for ( size_t j = 0 ; j < storage . getRowsTTL ( ) . group_by_keys . size ( ) ; + + j ) <nl> + for ( size_t j = 0 ; j < storage_rows_ttl . group_by_keys . size ( ) ; + + j ) <nl> { <nl> - const String & key_column = storage . getRowsTTL ( ) . group_by_keys [ j ] ; <nl> + const String & key_column = storage_rows_ttl . group_by_keys [ j ] ; <nl> const IColumn * values_column = block . getByName ( key_column ) . column . get ( ) ; <nl> if ( ! same_as_current | | ( * values_column ) [ i ] ! = current_key_value [ j ] ) <nl> { <nl> void TTLBlockInputStream : : finalizeAggregates ( MutableColumns & result_columns ) <nl> if ( ! agg_result . empty ( ) ) <nl> { <nl> auto aggregated_res = aggregator - > convertToBlocks ( agg_result , true , 1 ) ; <nl> + auto storage_rows_ttl = storage . getRowsTTL ( ) ; <nl> for ( auto & agg_block : aggregated_res ) <nl> { <nl> - for ( const auto & it : storage . getRowsTTL ( ) . set_parts ) <nl> + for ( const auto & it : storage_rows_ttl . set_parts ) <nl> it . expression - > execute ( agg_block ) ; <nl> - for ( const auto & name : storage . getRowsTTL ( ) . group_by_keys ) <nl> + for ( const auto & name : storage_rows_ttl . group_by_keys ) <nl> { <nl> const IColumn * values_column = agg_block . getByName ( name ) . column . get ( ) ; <nl> auto & result_column = result_columns [ header . getPositionByName ( name ) ] ; <nl> result_column - > insertRangeFrom ( * values_column , 0 , agg_block . rows ( ) ) ; <nl> } <nl> - for ( const auto & it : storage . getRowsTTL ( ) . set_parts ) <nl> + for ( const auto & it : storage_rows_ttl . set_parts ) <nl> { <nl> const IColumn * values_column = agg_block . getByName ( it . expression_result_column_name ) . column . get ( ) ; <nl> auto & result_column = result_columns [ header . getPositionByName ( it . column_name ) ] ; <nl> mmm a / src / Databases / DatabaseOrdinary . cpp <nl> ppp b / src / Databases / DatabaseOrdinary . cpp <nl> void DatabaseOrdinary : : alterTable ( <nl> ast_create_query . columns_list - > setOrReplace ( ast_create_query . columns_list - > indices , new_indices ) ; <nl> ast_create_query . columns_list - > setOrReplace ( ast_create_query . columns_list - > constraints , new_constraints ) ; <nl> <nl> - if ( metadata . select ) <nl> + if ( metadata . select . select_query ) <nl> { <nl> - ast - > replace ( ast_create_query . select , metadata . select ) ; <nl> + ast - > replace ( ast_create_query . select , metadata . select . select_query ) ; <nl> } <nl> <nl> / / / MaterializedView is one type of CREATE query without storage . <nl> void DatabaseOrdinary : : alterTable ( <nl> { <nl> ASTStorage & storage_ast = * ast_create_query . storage ; <nl> / / / ORDER BY may change , but cannot appear , it ' s required construction <nl> - if ( metadata . order_by_ast & & storage_ast . order_by ) <nl> - storage_ast . set ( storage_ast . order_by , metadata . order_by_ast ) ; <nl> + if ( metadata . sorting_key . definition_ast & & storage_ast . order_by ) <nl> + storage_ast . set ( storage_ast . order_by , metadata . sorting_key . definition_ast ) ; <nl> <nl> - if ( metadata . primary_key_ast ) <nl> - storage_ast . set ( storage_ast . primary_key , metadata . primary_key_ast ) ; <nl> + if ( metadata . primary_key . definition_ast ) <nl> + storage_ast . set ( storage_ast . primary_key , metadata . primary_key . definition_ast ) ; <nl> <nl> - if ( metadata . ttl_for_table_ast ) <nl> - storage_ast . set ( storage_ast . ttl_table , metadata . ttl_for_table_ast ) ; <nl> + if ( metadata . table_ttl . definition_ast ) <nl> + storage_ast . set ( storage_ast . ttl_table , metadata . table_ttl . definition_ast ) ; <nl> <nl> - if ( metadata . settings_ast ) <nl> - storage_ast . set ( storage_ast . settings , metadata . settings_ast ) ; <nl> + if ( metadata . settings_changes ) <nl> + storage_ast . set ( storage_ast . settings , metadata . settings_changes ) ; <nl> } <nl> <nl> statement = getObjectDefinitionFromCreateQuery ( ast ) ; <nl> mmm a / src / Interpreters / ExpressionActions . h <nl> ppp b / src / Interpreters / ExpressionActions . h <nl> class ExpressionActions <nl> <nl> ~ ExpressionActions ( ) ; <nl> <nl> + ExpressionActions ( const ExpressionActions & other ) = default ; <nl> + <nl> / / / Add the input column . <nl> / / / The name of the column must not match the names of the intermediate columns that occur when evaluating the expression . <nl> / / / The expression must not have any PROJECT actions . <nl> mmm a / src / Storages / AlterCommands . cpp <nl> ppp b / src / Storages / AlterCommands . cpp <nl> void AlterCommand : : apply ( StorageInMemoryMetadata & metadata , const Context & con <nl> column . default_desc . expression = default_expression ; <nl> } <nl> } ) ; <nl> + <nl> } <nl> else if ( type = = MODIFY_ORDER_BY ) <nl> { <nl> - if ( ! metadata . primary_key_ast & & metadata . order_by_ast ) <nl> + auto & sorting_key = metadata . sorting_key ; <nl> + auto & primary_key = metadata . primary_key ; <nl> + if ( primary_key . definition_ast = = nullptr & & sorting_key . definition_ast ! = nullptr ) <nl> { <nl> - / / / Primary and sorting key become independent after this ALTER so we have to <nl> - / / / save the old ORDER BY expression as the new primary key . <nl> - metadata . primary_key_ast = metadata . order_by_ast - > clone ( ) ; <nl> + / / / Primary and sorting key become independent after this ALTER so <nl> + / / / we have to save the old ORDER BY expression as the new primary <nl> + / / / key . <nl> + primary_key = KeyDescription : : getKeyFromAST ( sorting_key . definition_ast , metadata . columns , context ) ; <nl> } <nl> <nl> - metadata . order_by_ast = order_by ; <nl> + / / / Recalculate key with new order_by expression . <nl> + sorting_key . recalculateWithNewAST ( order_by , metadata . columns , context ) ; <nl> } <nl> else if ( type = = COMMENT_COLUMN ) <nl> { <nl> - metadata . columns . modify ( column_name , [ & ] ( ColumnDescription & column ) { column . comment = * comment ; } ) ; <nl> + metadata . columns . modify ( column_name , <nl> + [ & ] ( ColumnDescription & column ) { column . comment = * comment ; } ) ; <nl> } <nl> else if ( type = = ADD_INDEX ) <nl> { <nl> void AlterCommand : : apply ( StorageInMemoryMetadata & metadata , const Context & con <nl> } <nl> else if ( type = = MODIFY_TTL ) <nl> { <nl> - metadata . ttl_for_table_ast = ttl ; <nl> + metadata . table_ttl = TTLTableDescription : : getTTLForTableFromAST ( ttl , metadata . columns , context , metadata . primary_key ) ; <nl> } <nl> else if ( type = = MODIFY_QUERY ) <nl> { <nl> - metadata . select = select ; <nl> + metadata . select = SelectQueryDescription : : getSelectQueryFromASTForMatView ( select , context ) ; <nl> } <nl> else if ( type = = MODIFY_SETTING ) <nl> { <nl> - auto & settings_from_storage = metadata . settings_ast - > as < ASTSetQuery & > ( ) . changes ; <nl> + auto & settings_from_storage = metadata . settings_changes - > as < ASTSetQuery & > ( ) . changes ; <nl> for ( const auto & change : settings_changes ) <nl> { <nl> auto finder = [ & change ] ( const SettingChange & c ) { return c . name = = change . name ; } ; <nl> void AlterCommand : : apply ( StorageInMemoryMetadata & metadata , const Context & con <nl> rename_visitor . visit ( column_to_modify . ttl ) ; <nl> } ) ; <nl> } <nl> - if ( metadata . ttl_for_table_ast ) <nl> - rename_visitor . visit ( metadata . ttl_for_table_ast ) ; <nl> + if ( metadata . table_ttl . definition_ast ) <nl> + rename_visitor . visit ( metadata . table_ttl . definition_ast ) ; <nl> + <nl> + metadata . table_ttl = TTLTableDescription : : getTTLForTableFromAST ( <nl> + metadata . table_ttl . definition_ast , metadata . columns , context , metadata . primary_key ) ; <nl> <nl> for ( auto & constraint : metadata . constraints . constraints ) <nl> rename_visitor . visit ( constraint ) ; <nl> void AlterCommands : : apply ( StorageInMemoryMetadata & metadata , const Context & co <nl> if ( ! command . ignore ) <nl> command . apply ( metadata_copy , context ) ; <nl> <nl> + / / / Changes in columns may lead to changes in keys expression . <nl> + metadata_copy . sorting_key . recalculateWithNewColumns ( metadata_copy . columns , context ) ; <nl> + if ( metadata_copy . primary_key . definition_ast ! = nullptr ) <nl> + { <nl> + metadata_copy . primary_key . recalculateWithNewColumns ( metadata_copy . columns , context ) ; <nl> + } <nl> + else <nl> + { <nl> + metadata_copy . primary_key = KeyDescription : : getKeyFromAST ( metadata_copy . sorting_key . definition_ast , metadata_copy . columns , context ) ; <nl> + metadata_copy . primary_key . definition_ast = nullptr ; <nl> + } <nl> + <nl> + / / / Changes in columns may lead to changes in TTL expressions . <nl> + auto column_ttl_asts = metadata_copy . columns . getColumnTTLs ( ) ; <nl> + for ( const auto & [ name , ast ] : column_ttl_asts ) <nl> + { <nl> + auto new_ttl_entry = TTLDescription : : getTTLFromAST ( ast , metadata_copy . columns , context , metadata_copy . primary_key ) ; <nl> + metadata_copy . column_ttls_by_name [ name ] = new_ttl_entry ; <nl> + } <nl> + <nl> + if ( metadata_copy . table_ttl . definition_ast ! = nullptr ) <nl> + metadata . table_ttl = TTLTableDescription : : getTTLForTableFromAST ( <nl> + metadata_copy . table_ttl . definition_ast , metadata_copy . columns , context , metadata_copy . primary_key ) ; <nl> + <nl> metadata = std : : move ( metadata_copy ) ; <nl> } <nl> <nl> void AlterCommands : : validate ( const StorageInMemoryMetadata & metadata , const Con <nl> } <nl> else if ( command . type = = AlterCommand : : MODIFY_SETTING ) <nl> { <nl> - if ( metadata . settings_ast = = nullptr ) <nl> + if ( metadata . settings_changes = = nullptr ) <nl> throw Exception { " Cannot alter settings , because table engine doesn ' t support settings changes " , ErrorCodes : : BAD_ARGUMENTS } ; <nl> } <nl> else if ( command . type = = AlterCommand : : RENAME_COLUMN ) <nl> mmm a / src / Storages / ConstraintsDescription . cpp <nl> ppp b / src / Storages / ConstraintsDescription . cpp <nl> ConstraintsExpressions ConstraintsDescription : : getExpressions ( const DB : : Context <nl> return res ; <nl> } <nl> <nl> + ConstraintsDescription : : ConstraintsDescription ( const ConstraintsDescription & other ) <nl> + { <nl> + constraints . reserve ( other . constraints . size ( ) ) ; <nl> + for ( const auto & constraint : other . constraints ) <nl> + constraints . emplace_back ( constraint - > clone ( ) ) ; <nl> + } <nl> + <nl> + ConstraintsDescription & ConstraintsDescription : : operator = ( const ConstraintsDescription & other ) <nl> + { <nl> + constraints . resize ( other . constraints . size ( ) ) ; <nl> + for ( size_t i = 0 ; i < constraints . size ( ) ; + + i ) <nl> + constraints [ i ] = other . constraints [ i ] - > clone ( ) ; <nl> + return * this ; <nl> + } <nl> + <nl> } <nl> mmm a / src / Storages / ConstraintsDescription . h <nl> ppp b / src / Storages / ConstraintsDescription . h <nl> struct ConstraintsDescription <nl> static ConstraintsDescription parse ( const String & str ) ; <nl> <nl> ConstraintsExpressions getExpressions ( const Context & context , const NamesAndTypesList & source_columns_ ) const ; <nl> + <nl> + ConstraintsDescription ( const ConstraintsDescription & other ) ; <nl> + ConstraintsDescription & operator = ( const ConstraintsDescription & other ) ; <nl> } ; <nl> <nl> } <nl> mmm a / src / Storages / IStorage . cpp <nl> ppp b / src / Storages / IStorage . cpp <nl> namespace ErrorCodes <nl> <nl> const ColumnsDescription & IStorage : : getColumns ( ) const <nl> { <nl> - return columns ; <nl> + return metadata . columns ; <nl> } <nl> <nl> const IndicesDescription & IStorage : : getSecondaryIndices ( ) const <nl> { <nl> - return secondary_indices ; <nl> + return metadata . secondary_indices ; <nl> } <nl> <nl> - <nl> bool IStorage : : hasSecondaryIndices ( ) const <nl> { <nl> - return ! secondary_indices . empty ( ) ; <nl> + return ! metadata . secondary_indices . empty ( ) ; <nl> } <nl> <nl> const ConstraintsDescription & IStorage : : getConstraints ( ) const <nl> { <nl> - return constraints ; <nl> + return metadata . constraints ; <nl> } <nl> <nl> Block IStorage : : getSampleBlock ( ) const <nl> void IStorage : : setColumns ( ColumnsDescription columns_ ) <nl> { <nl> if ( columns_ . getOrdinary ( ) . empty ( ) ) <nl> throw Exception ( " Empty list of columns passed " , ErrorCodes : : EMPTY_LIST_OF_COLUMNS_PASSED ) ; <nl> - columns = std : : move ( columns_ ) ; <nl> + metadata . columns = std : : move ( columns_ ) ; <nl> } <nl> <nl> void IStorage : : setSecondaryIndices ( IndicesDescription secondary_indices_ ) <nl> { <nl> - secondary_indices = std : : move ( secondary_indices_ ) ; <nl> + metadata . secondary_indices = std : : move ( secondary_indices_ ) ; <nl> } <nl> <nl> void IStorage : : setConstraints ( ConstraintsDescription constraints_ ) <nl> { <nl> - constraints = std : : move ( constraints_ ) ; <nl> + metadata . constraints = std : : move ( constraints_ ) ; <nl> } <nl> <nl> bool IStorage : : isVirtualColumn ( const String & column_name ) const <nl> TableStructureWriteLockHolder IStorage : : lockExclusively ( const String & query_id , <nl> return result ; <nl> } <nl> <nl> - StorageInMemoryMetadata IStorage : : getInMemoryMetadata ( ) const <nl> - { <nl> - return StorageInMemoryMetadata ( getColumns ( ) , getSecondaryIndices ( ) , getConstraints ( ) ) ; <nl> - } <nl> - <nl> void IStorage : : alter ( <nl> const AlterCommands & params , <nl> const Context & context , <nl> void IStorage : : alter ( <nl> { <nl> lockStructureExclusively ( table_lock_holder , context . getCurrentQueryId ( ) , context . getSettingsRef ( ) . lock_acquire_timeout ) ; <nl> auto table_id = getStorageID ( ) ; <nl> - StorageInMemoryMetadata metadata = getInMemoryMetadata ( ) ; <nl> - params . apply ( metadata , context ) ; <nl> - DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , metadata ) ; <nl> - setColumns ( std : : move ( metadata . columns ) ) ; <nl> + StorageInMemoryMetadata new_metadata = getInMemoryMetadata ( ) ; <nl> + params . apply ( new_metadata , context ) ; <nl> + DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , new_metadata ) ; <nl> + setColumns ( std : : move ( new_metadata . columns ) ) ; <nl> } <nl> <nl> <nl> - void IStorage : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) <nl> + void IStorage : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) const <nl> { <nl> for ( const auto & command : commands ) <nl> { <nl> NamesAndTypesList IStorage : : getVirtuals ( ) const <nl> return { } ; <nl> } <nl> <nl> - const StorageMetadataKeyField & IStorage : : getPartitionKey ( ) const <nl> + const KeyDescription & IStorage : : getPartitionKey ( ) const <nl> { <nl> - return partition_key ; <nl> + return metadata . partition_key ; <nl> } <nl> <nl> - void IStorage : : setPartitionKey ( const StorageMetadataKeyField & partition_key_ ) <nl> + void IStorage : : setPartitionKey ( const KeyDescription & partition_key_ ) <nl> { <nl> - partition_key = partition_key_ ; <nl> + metadata . partition_key = partition_key_ ; <nl> } <nl> <nl> bool IStorage : : isPartitionKeyDefined ( ) const <nl> { <nl> - return partition_key . definition_ast ! = nullptr ; <nl> + return metadata . partition_key . definition_ast ! = nullptr ; <nl> } <nl> <nl> bool IStorage : : hasPartitionKey ( ) const <nl> { <nl> - return ! partition_key . column_names . empty ( ) ; <nl> + return ! metadata . partition_key . column_names . empty ( ) ; <nl> } <nl> <nl> Names IStorage : : getColumnsRequiredForPartitionKey ( ) const <nl> { <nl> if ( hasPartitionKey ( ) ) <nl> - return partition_key . expression - > getRequiredColumns ( ) ; <nl> + return metadata . partition_key . expression - > getRequiredColumns ( ) ; <nl> return { } ; <nl> } <nl> <nl> - const StorageMetadataKeyField & IStorage : : getSortingKey ( ) const <nl> + const KeyDescription & IStorage : : getSortingKey ( ) const <nl> { <nl> - return sorting_key ; <nl> + return metadata . sorting_key ; <nl> } <nl> <nl> - void IStorage : : setSortingKey ( const StorageMetadataKeyField & sorting_key_ ) <nl> + void IStorage : : setSortingKey ( const KeyDescription & sorting_key_ ) <nl> { <nl> - sorting_key = sorting_key_ ; <nl> + metadata . sorting_key = sorting_key_ ; <nl> } <nl> <nl> bool IStorage : : isSortingKeyDefined ( ) const <nl> { <nl> - return sorting_key . definition_ast ! = nullptr ; <nl> + return metadata . sorting_key . definition_ast ! = nullptr ; <nl> } <nl> <nl> bool IStorage : : hasSortingKey ( ) const <nl> { <nl> - return ! sorting_key . column_names . empty ( ) ; <nl> + return ! metadata . sorting_key . column_names . empty ( ) ; <nl> } <nl> <nl> Names IStorage : : getColumnsRequiredForSortingKey ( ) const <nl> { <nl> if ( hasSortingKey ( ) ) <nl> - return sorting_key . expression - > getRequiredColumns ( ) ; <nl> + return metadata . sorting_key . expression - > getRequiredColumns ( ) ; <nl> return { } ; <nl> } <nl> <nl> Names IStorage : : getSortingKeyColumns ( ) const <nl> { <nl> if ( hasSortingKey ( ) ) <nl> - return sorting_key . column_names ; <nl> + return metadata . sorting_key . column_names ; <nl> return { } ; <nl> } <nl> <nl> - const StorageMetadataKeyField & IStorage : : getPrimaryKey ( ) const <nl> + const KeyDescription & IStorage : : getPrimaryKey ( ) const <nl> { <nl> - return primary_key ; <nl> + return metadata . primary_key ; <nl> } <nl> <nl> - void IStorage : : setPrimaryKey ( const StorageMetadataKeyField & primary_key_ ) <nl> + void IStorage : : setPrimaryKey ( const KeyDescription & primary_key_ ) <nl> { <nl> - primary_key = primary_key_ ; <nl> + metadata . primary_key = primary_key_ ; <nl> } <nl> <nl> bool IStorage : : isPrimaryKeyDefined ( ) const <nl> { <nl> - return primary_key . definition_ast ! = nullptr ; <nl> + return metadata . primary_key . definition_ast ! = nullptr ; <nl> } <nl> <nl> bool IStorage : : hasPrimaryKey ( ) const <nl> { <nl> - return ! primary_key . column_names . empty ( ) ; <nl> + return ! metadata . primary_key . column_names . empty ( ) ; <nl> } <nl> <nl> Names IStorage : : getColumnsRequiredForPrimaryKey ( ) const <nl> { <nl> if ( hasPrimaryKey ( ) ) <nl> - return primary_key . expression - > getRequiredColumns ( ) ; <nl> + return metadata . primary_key . expression - > getRequiredColumns ( ) ; <nl> return { } ; <nl> } <nl> <nl> Names IStorage : : getPrimaryKeyColumns ( ) const <nl> { <nl> - if ( hasSortingKey ( ) ) <nl> - return primary_key . column_names ; <nl> + if ( ! metadata . primary_key . column_names . empty ( ) ) <nl> + return metadata . primary_key . column_names ; <nl> return { } ; <nl> } <nl> <nl> - const StorageMetadataKeyField & IStorage : : getSamplingKey ( ) const <nl> + const KeyDescription & IStorage : : getSamplingKey ( ) const <nl> { <nl> - return sampling_key ; <nl> + return metadata . sampling_key ; <nl> } <nl> <nl> - void IStorage : : setSamplingKey ( const StorageMetadataKeyField & sampling_key_ ) <nl> + void IStorage : : setSamplingKey ( const KeyDescription & sampling_key_ ) <nl> { <nl> - sampling_key = sampling_key_ ; <nl> + metadata . sampling_key = sampling_key_ ; <nl> } <nl> <nl> <nl> bool IStorage : : isSamplingKeyDefined ( ) const <nl> { <nl> - return sampling_key . definition_ast ! = nullptr ; <nl> + return metadata . sampling_key . definition_ast ! = nullptr ; <nl> } <nl> <nl> bool IStorage : : hasSamplingKey ( ) const <nl> { <nl> - return ! sampling_key . column_names . empty ( ) ; <nl> + return ! metadata . sampling_key . column_names . empty ( ) ; <nl> } <nl> <nl> Names IStorage : : getColumnsRequiredForSampling ( ) const <nl> { <nl> if ( hasSamplingKey ( ) ) <nl> - return sampling_key . expression - > getRequiredColumns ( ) ; <nl> + return metadata . sampling_key . expression - > getRequiredColumns ( ) ; <nl> return { } ; <nl> } <nl> <nl> - const TTLTableDescription & IStorage : : getTableTTLs ( ) const <nl> + TTLTableDescription IStorage : : getTableTTLs ( ) const <nl> { <nl> - return table_ttl ; <nl> + std : : lock_guard lock ( ttl_mutex ) ; <nl> + return metadata . table_ttl ; <nl> } <nl> <nl> void IStorage : : setTableTTLs ( const TTLTableDescription & table_ttl_ ) <nl> { <nl> - table_ttl = table_ttl_ ; <nl> + std : : lock_guard lock ( ttl_mutex ) ; <nl> + metadata . table_ttl = table_ttl_ ; <nl> } <nl> <nl> bool IStorage : : hasAnyTableTTL ( ) const <nl> bool IStorage : : hasAnyTableTTL ( ) const <nl> return hasAnyMoveTTL ( ) | | hasRowsTTL ( ) ; <nl> } <nl> <nl> - const TTLColumnsDescription & IStorage : : getColumnTTLs ( ) const <nl> + TTLColumnsDescription IStorage : : getColumnTTLs ( ) const <nl> { <nl> - return column_ttls_by_name ; <nl> + std : : lock_guard lock ( ttl_mutex ) ; <nl> + return metadata . column_ttls_by_name ; <nl> } <nl> <nl> void IStorage : : setColumnTTLs ( const TTLColumnsDescription & column_ttls_by_name_ ) <nl> { <nl> - column_ttls_by_name = column_ttls_by_name_ ; <nl> + std : : lock_guard lock ( ttl_mutex ) ; <nl> + metadata . column_ttls_by_name = column_ttls_by_name_ ; <nl> } <nl> <nl> bool IStorage : : hasAnyColumnTTL ( ) const <nl> { <nl> - return ! column_ttls_by_name . empty ( ) ; <nl> + std : : lock_guard lock ( ttl_mutex ) ; <nl> + return ! metadata . column_ttls_by_name . empty ( ) ; <nl> } <nl> <nl> - const TTLDescription & IStorage : : getRowsTTL ( ) const <nl> + TTLDescription IStorage : : getRowsTTL ( ) const <nl> { <nl> - return table_ttl . rows_ttl ; <nl> + std : : lock_guard lock ( ttl_mutex ) ; <nl> + return metadata . table_ttl . rows_ttl ; <nl> } <nl> <nl> bool IStorage : : hasRowsTTL ( ) const <nl> { <nl> - return table_ttl . rows_ttl . expression ! = nullptr ; <nl> + std : : lock_guard lock ( ttl_mutex ) ; <nl> + return metadata . table_ttl . rows_ttl . expression ! = nullptr ; <nl> } <nl> <nl> - const TTLDescriptions & IStorage : : getMoveTTLs ( ) const <nl> + TTLDescriptions IStorage : : getMoveTTLs ( ) const <nl> { <nl> - return table_ttl . move_ttl ; <nl> + std : : lock_guard lock ( ttl_mutex ) ; <nl> + return metadata . table_ttl . move_ttl ; <nl> } <nl> <nl> bool IStorage : : hasAnyMoveTTL ( ) const <nl> { <nl> - return ! table_ttl . move_ttl . empty ( ) ; <nl> + std : : lock_guard lock ( ttl_mutex ) ; <nl> + return ! metadata . table_ttl . move_ttl . empty ( ) ; <nl> } <nl> <nl> <nl> ColumnDependencies IStorage : : getColumnDependencies ( const NameSet & updated_colum <nl> <nl> if ( hasRowsTTL ( ) ) <nl> { <nl> - if ( add_dependent_columns ( getRowsTTL ( ) . expression , required_ttl_columns ) ) <nl> + auto rows_expression = getRowsTTL ( ) . expression ; <nl> + if ( add_dependent_columns ( rows_expression , required_ttl_columns ) ) <nl> { <nl> / / / Filter all columns , if rows TTL expression have to be recalculated . <nl> for ( const auto & column : getColumns ( ) . getAllPhysical ( ) ) <nl> ColumnDependencies IStorage : : getColumnDependencies ( const NameSet & updated_colum <nl> <nl> } <nl> <nl> + ASTPtr IStorage : : getSettingsChanges ( ) const <nl> + { <nl> + if ( metadata . settings_changes ) <nl> + return metadata . settings_changes - > clone ( ) ; <nl> + return nullptr ; <nl> + } <nl> + <nl> + void IStorage : : setSettingsChanges ( const ASTPtr & settings_changes_ ) <nl> + { <nl> + if ( settings_changes_ ) <nl> + metadata . settings_changes = settings_changes_ - > clone ( ) ; <nl> + else <nl> + metadata . settings_changes = nullptr ; <nl> + } <nl> + <nl> + const SelectQueryDescription & IStorage : : getSelectQuery ( ) const <nl> + { <nl> + return metadata . select ; <nl> + } <nl> + <nl> + void IStorage : : setSelectQuery ( const SelectQueryDescription & select_ ) <nl> + { <nl> + metadata . select = select_ ; <nl> + } <nl> + <nl> + bool IStorage : : hasSelectQuery ( ) const <nl> + { <nl> + return metadata . select . select_query ! = nullptr ; <nl> + } <nl> + <nl> } <nl> mmm a / src / Storages / IStorage . h <nl> ppp b / src / Storages / IStorage . h <nl> <nl> # include < Storages / SelectQueryInfo . h > <nl> # include < Storages / TableStructureLockHolder . h > <nl> # include < Storages / CheckResults . h > <nl> - # include < Storages / ColumnsDescription . h > <nl> - # include < Storages / IndicesDescription . h > <nl> - # include < Storages / ConstraintsDescription . h > <nl> # include < Storages / StorageInMemoryMetadata . h > <nl> - # include < Storages / TTLDescription . h > <nl> # include < Storages / ColumnDependency . h > <nl> + # include < Storages / SelectQueryDescription . h > <nl> # include < Common / ActionLock . h > <nl> # include < Common / Exception . h > <nl> # include < Common / RWLock . h > <nl> class IStorage : public std : : enable_shared_from_this < IStorage > , public TypePromo <nl> virtual ColumnSizeByName getColumnSizes ( ) const { return { } ; } <nl> <nl> public : / / / thread - unsafe part . lockStructure must be acquired <nl> + <nl> const ColumnsDescription & getColumns ( ) const ; / / / returns combined set of columns <nl> void setColumns ( ColumnsDescription columns_ ) ; / / / sets only real columns , possibly overwrites virtual ones . <nl> <nl> class IStorage : public std : : enable_shared_from_this < IStorage > , public TypePromo <nl> const ConstraintsDescription & getConstraints ( ) const ; <nl> void setConstraints ( ConstraintsDescription constraints_ ) ; <nl> <nl> - / / / Returns storage metadata copy . Direct modification of <nl> - / / / result structure doesn ' t affect storage . <nl> - virtual StorageInMemoryMetadata getInMemoryMetadata ( ) const ; <nl> + / / / Storage settings <nl> + ASTPtr getSettingsChanges ( ) const ; <nl> + void setSettingsChanges ( const ASTPtr & settings_changes_ ) ; <nl> + bool hasSettingsChanges ( ) const { return metadata . settings_changes ! = nullptr ; } <nl> + <nl> + / / / Select query for * View storages . <nl> + const SelectQueryDescription & getSelectQuery ( ) const ; <nl> + void setSelectQuery ( const SelectQueryDescription & select_ ) ; <nl> + bool hasSelectQuery ( ) const ; <nl> + <nl> + StorageInMemoryMetadata getInMemoryMetadata ( ) const { return metadata ; } <nl> <nl> Block getSampleBlock ( ) const ; / / / ordinary + materialized . <nl> Block getSampleBlockWithVirtuals ( ) const ; / / / ordinary + materialized + virtuals . <nl> class IStorage : public std : : enable_shared_from_this < IStorage > , public TypePromo <nl> StorageID storage_id ; <nl> mutable std : : mutex id_mutex ; <nl> <nl> - ColumnsDescription columns ; <nl> - IndicesDescription secondary_indices ; <nl> - ConstraintsDescription constraints ; <nl> - <nl> - StorageMetadataKeyField partition_key ; <nl> - StorageMetadataKeyField primary_key ; <nl> - StorageMetadataKeyField sorting_key ; <nl> - StorageMetadataKeyField sampling_key ; <nl> - <nl> - TTLColumnsDescription column_ttls_by_name ; <nl> - TTLTableDescription table_ttl ; <nl> - <nl> + / / / TODO ( alesap ) just use multiversion for atomic metadata <nl> + mutable std : : mutex ttl_mutex ; <nl> + StorageInMemoryMetadata metadata ; <nl> private : <nl> RWLockImpl : : LockHolder tryLockTimed ( <nl> const RWLock & rwlock , RWLockImpl : : Type type , const String & query_id , const SettingSeconds & acquire_timeout ) const ; <nl> class IStorage : public std : : enable_shared_from_this < IStorage > , public TypePromo <nl> / * * Checks that alter commands can be applied to storage . For example , columns can be modified , <nl> * or primary key can be changes , etc . <nl> * / <nl> - virtual void checkAlterIsPossible ( const AlterCommands & commands , const Settings & settings ) ; <nl> + virtual void checkAlterIsPossible ( const AlterCommands & commands , const Settings & settings ) const ; <nl> <nl> / * * ALTER tables with regard to its partitions . <nl> * Should handle locks for each command on its own . <nl> class IStorage : public std : : enable_shared_from_this < IStorage > , public TypePromo <nl> virtual Strings getDataPaths ( ) const { return { } ; } <nl> <nl> / / / Returns structure with partition key . <nl> - const StorageMetadataKeyField & getPartitionKey ( ) const ; <nl> + const KeyDescription & getPartitionKey ( ) const ; <nl> / / / Set partition key for storage ( methods bellow , are just wrappers for this <nl> / / / struct ) . <nl> - void setPartitionKey ( const StorageMetadataKeyField & partition_key_ ) ; <nl> + void setPartitionKey ( const KeyDescription & partition_key_ ) ; <nl> / / / Returns ASTExpressionList of partition key expression for storage or nullptr if there is none . <nl> - ASTPtr getPartitionKeyAST ( ) const { return partition_key . definition_ast ; } <nl> + ASTPtr getPartitionKeyAST ( ) const { return metadata . partition_key . definition_ast ; } <nl> / / / Storage has user - defined ( in CREATE query ) partition key . <nl> bool isPartitionKeyDefined ( ) const ; <nl> / / / Storage has partition key . <nl> class IStorage : public std : : enable_shared_from_this < IStorage > , public TypePromo <nl> <nl> <nl> / / / Returns structure with sorting key . <nl> - const StorageMetadataKeyField & getSortingKey ( ) const ; <nl> + const KeyDescription & getSortingKey ( ) const ; <nl> / / / Set sorting key for storage ( methods bellow , are just wrappers for this <nl> / / / struct ) . <nl> - void setSortingKey ( const StorageMetadataKeyField & sorting_key_ ) ; <nl> + void setSortingKey ( const KeyDescription & sorting_key_ ) ; <nl> / / / Returns ASTExpressionList of sorting key expression for storage or nullptr if there is none . <nl> - ASTPtr getSortingKeyAST ( ) const { return sorting_key . definition_ast ; } <nl> + ASTPtr getSortingKeyAST ( ) const { return metadata . sorting_key . definition_ast ; } <nl> / / / Storage has user - defined ( in CREATE query ) sorting key . <nl> bool isSortingKeyDefined ( ) const ; <nl> / / / Storage has sorting key . It means , that it contains at least one column . <nl> class IStorage : public std : : enable_shared_from_this < IStorage > , public TypePromo <nl> Names getSortingKeyColumns ( ) const ; <nl> <nl> / / / Returns structure with primary key . <nl> - const StorageMetadataKeyField & getPrimaryKey ( ) const ; <nl> + const KeyDescription & getPrimaryKey ( ) const ; <nl> / / / Set primary key for storage ( methods bellow , are just wrappers for this <nl> / / / struct ) . <nl> - void setPrimaryKey ( const StorageMetadataKeyField & primary_key_ ) ; <nl> + void setPrimaryKey ( const KeyDescription & primary_key_ ) ; <nl> / / / Returns ASTExpressionList of primary key expression for storage or nullptr if there is none . <nl> - ASTPtr getPrimaryKeyAST ( ) const { return primary_key . definition_ast ; } <nl> + ASTPtr getPrimaryKeyAST ( ) const { return metadata . primary_key . definition_ast ; } <nl> / / / Storage has user - defined ( in CREATE query ) sorting key . <nl> bool isPrimaryKeyDefined ( ) const ; <nl> / / / Storage has primary key ( maybe part of some other key ) . It means , that <nl> class IStorage : public std : : enable_shared_from_this < IStorage > , public TypePromo <nl> Names getPrimaryKeyColumns ( ) const ; <nl> <nl> / / / Returns structure with sampling key . <nl> - const StorageMetadataKeyField & getSamplingKey ( ) const ; <nl> + const KeyDescription & getSamplingKey ( ) const ; <nl> / / / Set sampling key for storage ( methods bellow , are just wrappers for this <nl> / / / struct ) . <nl> - void setSamplingKey ( const StorageMetadataKeyField & sampling_key_ ) ; <nl> + void setSamplingKey ( const KeyDescription & sampling_key_ ) ; <nl> / / / Returns sampling expression AST for storage or nullptr if there is none . <nl> - ASTPtr getSamplingKeyAST ( ) const { return sampling_key . definition_ast ; } <nl> + ASTPtr getSamplingKeyAST ( ) const { return metadata . sampling_key . definition_ast ; } <nl> / / / Storage has user - defined ( in CREATE query ) sampling key . <nl> bool isSamplingKeyDefined ( ) const ; <nl> / / / Storage has sampling key . <nl> class IStorage : public std : : enable_shared_from_this < IStorage > , public TypePromo <nl> virtual StoragePolicyPtr getStoragePolicy ( ) const { return { } ; } <nl> <nl> / / / Common tables TTLs ( for rows and moves ) . <nl> - const TTLTableDescription & getTableTTLs ( ) const ; <nl> + TTLTableDescription getTableTTLs ( ) const ; <nl> void setTableTTLs ( const TTLTableDescription & table_ttl_ ) ; <nl> bool hasAnyTableTTL ( ) const ; <nl> <nl> / / / Separate TTLs for columns . <nl> - const TTLColumnsDescription & getColumnTTLs ( ) const ; <nl> + TTLColumnsDescription getColumnTTLs ( ) const ; <nl> void setColumnTTLs ( const TTLColumnsDescription & column_ttls_by_name_ ) ; <nl> bool hasAnyColumnTTL ( ) const ; <nl> <nl> / / / Just wrapper for table TTLs , return rows part of table TTLs . <nl> - const TTLDescription & getRowsTTL ( ) const ; <nl> + TTLDescription getRowsTTL ( ) const ; <nl> bool hasRowsTTL ( ) const ; <nl> <nl> / / / Just wrapper for table TTLs , return moves ( to disks or volumes ) parts of <nl> / / / table TTL . <nl> - const TTLDescriptions & getMoveTTLs ( ) const ; <nl> + TTLDescriptions getMoveTTLs ( ) const ; <nl> bool hasAnyMoveTTL ( ) const ; <nl> <nl> / / / If it is possible to quickly determine exact number of rows in the table at this moment of time , then return it . <nl> mmm a / src / Storages / IndicesDescription . cpp <nl> ppp b / src / Storages / IndicesDescription . cpp <nl> namespace ErrorCodes <nl> extern const int LOGICAL_ERROR ; <nl> } ; <nl> <nl> + IndexDescription : : IndexDescription ( const IndexDescription & other ) <nl> + : definition_ast ( other . definition_ast ? other . definition_ast - > clone ( ) : nullptr ) <nl> + , expression_list_ast ( other . expression_list_ast ? other . expression_list_ast - > clone ( ) : nullptr ) <nl> + , name ( other . name ) <nl> + , type ( other . type ) <nl> + , arguments ( other . arguments ) <nl> + , column_names ( other . column_names ) <nl> + , data_types ( other . data_types ) <nl> + , sample_block ( other . sample_block ) <nl> + , granularity ( other . granularity ) <nl> + { <nl> + if ( other . expression ) <nl> + expression = std : : make_shared < ExpressionActions > ( * other . expression ) ; <nl> + } <nl> + <nl> + <nl> + IndexDescription & IndexDescription : : operator = ( const IndexDescription & other ) <nl> + { <nl> + if ( & other = = this ) <nl> + return * this ; <nl> + <nl> + if ( other . definition_ast ) <nl> + definition_ast = other . definition_ast - > clone ( ) ; <nl> + else <nl> + definition_ast . reset ( ) ; <nl> + <nl> + if ( other . expression_list_ast ) <nl> + expression_list_ast = other . expression_list_ast - > clone ( ) ; <nl> + else <nl> + expression_list_ast . reset ( ) ; <nl> + <nl> + name = other . name ; <nl> + type = other . type ; <nl> + <nl> + if ( other . expression ) <nl> + expression = std : : make_shared < ExpressionActions > ( * other . expression ) ; <nl> + else <nl> + expression . reset ( ) ; <nl> + <nl> + arguments = other . arguments ; <nl> + column_names = other . column_names ; <nl> + data_types = other . data_types ; <nl> + sample_block = other . sample_block ; <nl> + granularity = other . granularity ; <nl> + return * this ; <nl> + } <nl> <nl> IndexDescription IndexDescription : : getIndexFromAST ( const ASTPtr & definition_ast , const ColumnsDescription & columns , const Context & context ) <nl> { <nl> mmm a / src / Storages / IndicesDescription . h <nl> ppp b / src / Storages / IndicesDescription . h <nl> struct IndexDescription <nl> <nl> / / / Parse index from definition AST <nl> static IndexDescription getIndexFromAST ( const ASTPtr & definition_ast , const ColumnsDescription & columns , const Context & context ) ; <nl> + <nl> + IndexDescription ( ) = default ; <nl> + <nl> + / / / We need custom copy constructors because we don ' t want <nl> + / / / unintentionaly share AST variables and modify them . <nl> + IndexDescription ( const IndexDescription & other ) ; <nl> + IndexDescription & operator = ( const IndexDescription & other ) ; <nl> } ; <nl> <nl> / / / All secondary indices in storage <nl> new file mode 100644 <nl> index 00000000000 . . 7d5b0d56008 <nl> mmm / dev / null <nl> ppp b / src / Storages / KeyDescription . cpp <nl> <nl> + # include < Storages / KeyDescription . h > <nl> + <nl> + # include < Functions / IFunction . h > <nl> + # include < Parsers / ASTIdentifier . h > <nl> + # include < Interpreters / ExpressionActions . h > <nl> + # include < Interpreters / ExpressionAnalyzer . h > <nl> + # include < Interpreters / SyntaxAnalyzer . h > <nl> + # include < Storages / extractKeyExpressionList . h > <nl> + <nl> + <nl> + namespace DB <nl> + { <nl> + <nl> + namespace ErrorCodes <nl> + { <nl> + extern const int LOGICAL_ERROR ; <nl> + } <nl> + <nl> + KeyDescription : : KeyDescription ( const KeyDescription & other ) <nl> + : definition_ast ( other . definition_ast ? other . definition_ast - > clone ( ) : nullptr ) <nl> + , expression_list_ast ( other . expression_list_ast ? other . expression_list_ast - > clone ( ) : nullptr ) <nl> + , sample_block ( other . sample_block ) <nl> + , column_names ( other . column_names ) <nl> + , data_types ( other . data_types ) <nl> + , additional_column ( other . additional_column ) <nl> + { <nl> + if ( other . expression ) <nl> + expression = std : : make_shared < ExpressionActions > ( * other . expression ) ; <nl> + } <nl> + <nl> + KeyDescription & KeyDescription : : operator = ( const KeyDescription & other ) <nl> + { <nl> + if ( & other = = this ) <nl> + return * this ; <nl> + <nl> + if ( other . definition_ast ) <nl> + definition_ast = other . definition_ast - > clone ( ) ; <nl> + else <nl> + definition_ast . reset ( ) ; <nl> + <nl> + if ( other . expression_list_ast ) <nl> + expression_list_ast = other . expression_list_ast - > clone ( ) ; <nl> + else <nl> + expression_list_ast . reset ( ) ; <nl> + <nl> + <nl> + if ( other . expression ) <nl> + expression = std : : make_shared < ExpressionActions > ( * other . expression ) ; <nl> + else <nl> + expression . reset ( ) ; <nl> + <nl> + sample_block = other . sample_block ; <nl> + column_names = other . column_names ; <nl> + data_types = other . data_types ; <nl> + <nl> + / / / additional_column is constant property It should never be lost . <nl> + if ( additional_column . has_value ( ) & & ! other . additional_column . has_value ( ) ) <nl> + throw Exception ( " Wrong key assignment , loosing additional_column " , ErrorCodes : : LOGICAL_ERROR ) ; <nl> + additional_column = other . additional_column ; <nl> + return * this ; <nl> + } <nl> + <nl> + <nl> + void KeyDescription : : recalculateWithNewAST ( <nl> + const ASTPtr & new_ast , <nl> + const ColumnsDescription & columns , <nl> + const Context & context ) <nl> + { <nl> + * this = getSortingKeyFromAST ( new_ast , columns , context , additional_column ) ; <nl> + } <nl> + <nl> + void KeyDescription : : recalculateWithNewColumns ( <nl> + const ColumnsDescription & new_columns , <nl> + const Context & context ) <nl> + { <nl> + * this = getSortingKeyFromAST ( definition_ast , new_columns , context , additional_column ) ; <nl> + } <nl> + <nl> + KeyDescription KeyDescription : : getKeyFromAST ( <nl> + const ASTPtr & definition_ast , <nl> + const ColumnsDescription & columns , <nl> + const Context & context ) <nl> + { <nl> + return getSortingKeyFromAST ( definition_ast , columns , context , { } ) ; <nl> + } <nl> + <nl> + KeyDescription KeyDescription : : getSortingKeyFromAST ( <nl> + const ASTPtr & definition_ast , <nl> + const ColumnsDescription & columns , <nl> + const Context & context , <nl> + const std : : optional < String > & additional_column ) <nl> + { <nl> + KeyDescription result ; <nl> + result . definition_ast = definition_ast ; <nl> + result . expression_list_ast = extractKeyExpressionList ( definition_ast ) ; <nl> + <nl> + if ( additional_column ) <nl> + { <nl> + result . additional_column = additional_column ; <nl> + ASTPtr column_identifier = std : : make_shared < ASTIdentifier > ( * additional_column ) ; <nl> + result . expression_list_ast - > children . push_back ( column_identifier ) ; <nl> + } <nl> + <nl> + const auto & children = result . expression_list_ast - > children ; <nl> + for ( const auto & child : children ) <nl> + result . column_names . emplace_back ( child - > getColumnName ( ) ) ; <nl> + <nl> + { <nl> + auto expr = result . expression_list_ast - > clone ( ) ; <nl> + auto syntax_result = SyntaxAnalyzer ( context ) . analyze ( expr , columns . getAllPhysical ( ) ) ; <nl> + / / / In expression we also need to store source columns <nl> + result . expression = ExpressionAnalyzer ( expr , syntax_result , context ) . getActions ( false ) ; <nl> + / / / In sample block we use just key columns <nl> + result . sample_block = ExpressionAnalyzer ( expr , syntax_result , context ) . getActions ( true ) - > getSampleBlock ( ) ; <nl> + } <nl> + <nl> + for ( size_t i = 0 ; i < result . sample_block . columns ( ) ; + + i ) <nl> + result . data_types . emplace_back ( result . sample_block . getByPosition ( i ) . type ) ; <nl> + <nl> + return result ; <nl> + } <nl> + <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . 7d1e7efb55f <nl> mmm / dev / null <nl> ppp b / src / Storages / KeyDescription . h <nl> <nl> + # pragma once <nl> + <nl> + # include < Interpreters / ExpressionActions . h > <nl> + # include < Parsers / IAST_fwd . h > <nl> + # include < Storages / ColumnsDescription . h > <nl> + <nl> + namespace DB <nl> + { <nl> + / / / Common structure for primary , partition and other storage keys <nl> + struct KeyDescription <nl> + { <nl> + / / / User defined AST in CREATE / ALTER query . This field may be empty , but key <nl> + / / / can exists because some of them maybe set implicitly ( for example , <nl> + / / / primary key in merge tree can be part of sorting key ) <nl> + ASTPtr definition_ast ; <nl> + <nl> + / / / ASTExpressionList with key fields , example : ( x , toStartOfMonth ( date ) ) ) . <nl> + ASTPtr expression_list_ast ; <nl> + <nl> + / / / Expression from expression_list_ast created by ExpressionAnalyzer . Useful , <nl> + / / / when you need to get required columns for key , example : a , date , b . <nl> + ExpressionActionsPtr expression ; <nl> + <nl> + / / / Sample block with key columns ( names , types , empty column ) <nl> + Block sample_block ; <nl> + <nl> + / / / Column names in key definition , example : x , toStartOfMonth ( date ) , a * b . <nl> + Names column_names ; <nl> + <nl> + / / / Types from sample block ordered in columns order . <nl> + DataTypes data_types ; <nl> + <nl> + / / / Additional key column added by storage type . Never changes after <nl> + / / / initialization with non empty value . Doesn ' t stored in definition_ast , <nl> + / / / but added to expression_list_ast and all its derivatives . <nl> + std : : optional < String > additional_column ; <nl> + <nl> + / / / Parse key structure from key definition . Requires all columns , available <nl> + / / / in storage . <nl> + static KeyDescription getKeyFromAST ( <nl> + const ASTPtr & definition_ast , <nl> + const ColumnsDescription & columns , <nl> + const Context & context ) ; <nl> + <nl> + / / / Sorting key can contain additional column defined by storage type ( like <nl> + / / / Version column in VersionedCollapsingMergeTree ) . <nl> + static KeyDescription getSortingKeyFromAST ( <nl> + const ASTPtr & definition_ast , <nl> + const ColumnsDescription & columns , <nl> + const Context & context , <nl> + const std : : optional < String > & additional_column ) ; <nl> + <nl> + / / / Recalculate all expressions and fields for key with new columns without <nl> + / / / changes in constant fields . Just wrapper for static methods . <nl> + void recalculateWithNewColumns ( <nl> + const ColumnsDescription & new_columns , <nl> + const Context & context ) ; <nl> + <nl> + / / / Recalculate all expressions and fields for key with new ast without <nl> + / / / changes in constant fields . Just wrapper for static methods . <nl> + void recalculateWithNewAST ( <nl> + const ASTPtr & new_ast , <nl> + const ColumnsDescription & columns , <nl> + const Context & context ) ; <nl> + <nl> + KeyDescription ( ) = default ; <nl> + <nl> + / / / We need custom copy constructors because we don ' t want <nl> + / / / unintentionaly share AST variables and modify them . <nl> + KeyDescription ( const KeyDescription & other ) ; <nl> + KeyDescription & operator = ( const KeyDescription & other ) ; <nl> + } ; <nl> + <nl> + } <nl> mmm a / src / Storages / LiveView / StorageLiveView . h <nl> ppp b / src / Storages / LiveView / StorageLiveView . h <nl> friend class LiveViewBlockOutputStream ; <nl> const Context & context ) ; <nl> <nl> private : <nl> + / / / TODO move to common struct SelectQueryDescription <nl> StorageID select_table_id = StorageID : : createEmpty ( ) ; / / / Will be initialized in constructor <nl> ASTPtr inner_query ; / / / stored query : SELECT * FROM ( SELECT a FROM A ) <nl> ASTPtr inner_subquery ; / / / stored query ' s innermost subquery if any <nl> mmm a / src / Storages / MergeTree / MergeTreeData . cpp <nl> ppp b / src / Storages / MergeTree / MergeTreeData . cpp <nl> namespace ErrorCodes <nl> extern const int READONLY_SETTING ; <nl> extern const int ABORTED ; <nl> extern const int UNKNOWN_PART_TYPE ; <nl> - extern const int UNEXPECTED_AST_STRUCTURE ; <nl> extern const int UNKNOWN_DISK ; <nl> extern const int NOT_ENOUGH_SPACE ; <nl> extern const int ALTER_OF_COLUMN_IS_FORBIDDEN ; <nl> const char * DELETE_ON_DESTROY_MARKER_PATH = " delete - on - destroy . txt " ; <nl> MergeTreeData : : MergeTreeData ( <nl> const StorageID & table_id_ , <nl> const String & relative_data_path_ , <nl> - const StorageInMemoryMetadata & metadata , <nl> + const StorageInMemoryMetadata & metadata_ , <nl> Context & context_ , <nl> const String & date_column_name , <nl> const MergingParams & merging_params_ , <nl> MergeTreeData : : MergeTreeData ( <nl> : IStorage ( table_id_ ) <nl> , global_context ( context_ ) <nl> , merging_params ( merging_params_ ) <nl> - , settings_ast ( metadata . settings_ast ) <nl> , require_part_metadata ( require_part_metadata_ ) <nl> , relative_data_path ( relative_data_path_ ) <nl> , broken_part_callback ( broken_part_callback_ ) <nl> MergeTreeData : : MergeTreeData ( <nl> if ( relative_data_path . empty ( ) ) <nl> throw Exception ( " MergeTree storages require data path " , ErrorCodes : : INCORRECT_FILE_NAME ) ; <nl> <nl> + setSettingsChanges ( metadata_ . settings_changes ) ; <nl> const auto settings = getSettings ( ) ; <nl> - setProperties ( metadata , / * only_check * / false , attach ) ; <nl> + setProperties ( metadata_ , attach ) ; <nl> <nl> / / / NOTE : using the same columns list as is read when performing actual merges . <nl> merging_params . check ( getColumns ( ) . getAllPhysical ( ) ) ; <nl> <nl> - if ( metadata . sample_by_ast ! = nullptr ) <nl> + if ( metadata_ . sampling_key . definition_ast ! = nullptr ) <nl> { <nl> - StorageMetadataKeyField candidate_sampling_key = StorageMetadataKeyField : : getKeyFromAST ( <nl> - metadata . sample_by_ast , getColumns ( ) , global_context ) ; <nl> - <nl> const auto & pk_sample_block = getPrimaryKey ( ) . sample_block ; <nl> - if ( ! pk_sample_block . has ( candidate_sampling_key . column_names [ 0 ] ) & & ! attach <nl> + if ( ! pk_sample_block . has ( metadata_ . sampling_key . column_names [ 0 ] ) & & ! attach <nl> & & ! settings - > compatibility_allow_sampling_expression_not_in_primary_key ) / / / This is for backward compatibility . <nl> throw Exception ( " Sampling expression must be present in the primary key " , ErrorCodes : : BAD_ARGUMENTS ) ; <nl> <nl> - setSamplingKey ( candidate_sampling_key ) ; <nl> + setSamplingKey ( metadata_ . sampling_key ) ; <nl> } <nl> <nl> MergeTreeDataFormatVersion min_format_version ( 0 ) ; <nl> MergeTreeData : : MergeTreeData ( <nl> try <nl> { <nl> auto partition_by_ast = makeASTFunction ( " toYYYYMM " , std : : make_shared < ASTIdentifier > ( date_column_name ) ) ; <nl> - initPartitionKey ( partition_by_ast ) ; <nl> + auto partition_key = KeyDescription : : getKeyFromAST ( partition_by_ast , getColumns ( ) , global_context ) ; <nl> + initPartitionKey ( partition_key ) ; <nl> <nl> if ( minmax_idx_date_column_pos = = - 1 ) <nl> throw Exception ( " Could not find Date column " , ErrorCodes : : BAD_TYPE_OF_FIELD ) ; <nl> MergeTreeData : : MergeTreeData ( <nl> else <nl> { <nl> is_custom_partitioned = true ; <nl> - initPartitionKey ( metadata . partition_by_ast ) ; <nl> + initPartitionKey ( metadata_ . partition_key ) ; <nl> min_format_version = MERGE_TREE_DATA_MIN_FORMAT_VERSION_WITH_CUSTOM_PARTITIONING ; <nl> } <nl> <nl> - setTTLExpressions ( metadata . columns , metadata . ttl_for_table_ast ) ; <nl> + setTTLExpressions ( metadata_ ) ; <nl> <nl> / / / format_file always contained on any data path <nl> PathWithDisk version_file ; <nl> MergeTreeData : : MergeTreeData ( <nl> LOG_WARNING ( log , " { } Settings ' min_bytes_for_wide_part ' and ' min_bytes_for_wide_part ' will be ignored . " , reason ) ; <nl> } <nl> <nl> - <nl> - StorageInMemoryMetadata MergeTreeData : : getInMemoryMetadata ( ) const <nl> - { <nl> - StorageInMemoryMetadata metadata ( getColumns ( ) , getSecondaryIndices ( ) , getConstraints ( ) ) ; <nl> - <nl> - if ( isPartitionKeyDefined ( ) ) <nl> - metadata . partition_by_ast = getPartitionKeyAST ( ) - > clone ( ) ; <nl> - <nl> - if ( isSortingKeyDefined ( ) ) <nl> - metadata . order_by_ast = getSortingKeyAST ( ) - > clone ( ) ; <nl> - <nl> - if ( isPrimaryKeyDefined ( ) ) <nl> - metadata . primary_key_ast = getPrimaryKeyAST ( ) - > clone ( ) ; <nl> - <nl> - if ( hasAnyTableTTL ( ) ) <nl> - metadata . ttl_for_table_ast = getTableTTLs ( ) . definition_ast - > clone ( ) ; <nl> - <nl> - if ( isSamplingKeyDefined ( ) ) <nl> - metadata . sample_by_ast = getSamplingKeyAST ( ) - > clone ( ) ; <nl> - <nl> - if ( settings_ast ) <nl> - metadata . settings_ast = settings_ast - > clone ( ) ; <nl> - <nl> - return metadata ; <nl> - } <nl> - <nl> StoragePolicyPtr MergeTreeData : : getStoragePolicy ( ) const <nl> { <nl> return global_context . getStoragePolicy ( getSettings ( ) - > storage_policy ) ; <nl> static void checkKeyExpression ( const ExpressionActions & expr , const Block & sam <nl> } <nl> } <nl> <nl> - void MergeTreeData : : setProperties ( const StorageInMemoryMetadata & metadata , bool only_check , bool attach ) <nl> + void MergeTreeData : : checkProperties ( const StorageInMemoryMetadata & new_metadata , bool attach ) const <nl> { <nl> - if ( ! metadata . order_by_ast ) <nl> + if ( ! new_metadata . sorting_key . definition_ast ) <nl> throw Exception ( " ORDER BY cannot be empty " , ErrorCodes : : BAD_ARGUMENTS ) ; <nl> <nl> - ASTPtr new_sorting_key_expr_list = extractKeyExpressionList ( metadata . order_by_ast ) ; <nl> - ASTPtr new_primary_key_expr_list = metadata . primary_key_ast <nl> - ? extractKeyExpressionList ( metadata . primary_key_ast ) : new_sorting_key_expr_list - > clone ( ) ; <nl> + KeyDescription new_sorting_key = new_metadata . sorting_key ; <nl> + KeyDescription new_primary_key = new_metadata . primary_key ; <nl> <nl> - if ( merging_params . mode = = MergeTreeData : : MergingParams : : VersionedCollapsing ) <nl> - new_sorting_key_expr_list - > children . push_back ( std : : make_shared < ASTIdentifier > ( merging_params . version_column ) ) ; <nl> - <nl> - size_t primary_key_size = new_primary_key_expr_list - > children . size ( ) ; <nl> - size_t sorting_key_size = new_sorting_key_expr_list - > children . size ( ) ; <nl> + size_t sorting_key_size = new_sorting_key . column_names . size ( ) ; <nl> + size_t primary_key_size = new_primary_key . column_names . size ( ) ; <nl> if ( primary_key_size > sorting_key_size ) <nl> throw Exception ( " Primary key must be a prefix of the sorting key , but its length : " <nl> + toString ( primary_key_size ) + " is greater than the sorting key length : " + toString ( sorting_key_size ) , <nl> ErrorCodes : : BAD_ARGUMENTS ) ; <nl> <nl> - Names new_primary_key_columns ; <nl> - Names new_sorting_key_columns ; <nl> NameSet primary_key_columns_set ; <nl> <nl> for ( size_t i = 0 ; i < sorting_key_size ; + + i ) <nl> { <nl> - String sorting_key_column = new_sorting_key_expr_list - > children [ i ] - > getColumnName ( ) ; <nl> - new_sorting_key_columns . push_back ( sorting_key_column ) ; <nl> + const String & sorting_key_column = new_sorting_key . column_names [ i ] ; <nl> <nl> if ( i < primary_key_size ) <nl> { <nl> - String pk_column = new_primary_key_expr_list - > children [ i ] - > getColumnName ( ) ; <nl> + const String & pk_column = new_primary_key . column_names [ i ] ; <nl> if ( pk_column ! = sorting_key_column ) <nl> throw Exception ( " Primary key must be a prefix of the sorting key , but in position " <nl> + toString ( i ) + " its column is " + pk_column + " , not " + sorting_key_column , <nl> void MergeTreeData : : setProperties ( const StorageInMemoryMetadata & metadata , bool <nl> if ( ! primary_key_columns_set . emplace ( pk_column ) . second ) <nl> throw Exception ( " Primary key contains duplicate columns " , ErrorCodes : : BAD_ARGUMENTS ) ; <nl> <nl> - new_primary_key_columns . push_back ( pk_column ) ; <nl> } <nl> } <nl> <nl> - auto all_columns = metadata . columns . getAllPhysical ( ) ; <nl> + auto all_columns = new_metadata . columns . getAllPhysical ( ) ; <nl> <nl> / / / Order by check AST <nl> - if ( hasSortingKey ( ) & & only_check ) <nl> + if ( hasSortingKey ( ) ) <nl> { <nl> / / / This is ALTER , not CREATE / ATTACH TABLE . Let us check that all new columns used in the sorting key <nl> / / / expression have just been added ( so that the sorting order is guaranteed to be valid with the new key ) . <nl> <nl> + Names new_primary_key_columns = new_primary_key . column_names ; <nl> + Names new_sorting_key_columns = new_sorting_key . column_names ; <nl> + <nl> ASTPtr added_key_column_expr_list = std : : make_shared < ASTExpressionList > ( ) ; <nl> const auto & old_sorting_key_columns = getSortingKeyColumns ( ) ; <nl> for ( size_t new_i = 0 , old_i = 0 ; new_i < sorting_key_size ; + + new_i ) <nl> void MergeTreeData : : setProperties ( const StorageInMemoryMetadata & metadata , bool <nl> if ( old_i < old_sorting_key_columns . size ( ) ) <nl> { <nl> if ( new_sorting_key_columns [ new_i ] ! = old_sorting_key_columns [ old_i ] ) <nl> - added_key_column_expr_list - > children . push_back ( new_sorting_key_expr_list - > children [ new_i ] ) ; <nl> + added_key_column_expr_list - > children . push_back ( new_sorting_key . expression_list_ast - > children [ new_i ] ) ; <nl> else <nl> + + old_i ; <nl> } <nl> else <nl> - added_key_column_expr_list - > children . push_back ( new_sorting_key_expr_list - > children [ new_i ] ) ; <nl> + added_key_column_expr_list - > children . push_back ( new_sorting_key . expression_list_ast - > children [ new_i ] ) ; <nl> } <nl> <nl> if ( ! added_key_column_expr_list - > children . empty ( ) ) <nl> void MergeTreeData : : setProperties ( const StorageInMemoryMetadata & metadata , bool <nl> " added to the sorting key . You can add expressions that use only the newly added columns " , <nl> ErrorCodes : : BAD_ARGUMENTS ) ; <nl> <nl> - if ( metadata . columns . getDefaults ( ) . count ( col ) ) <nl> + if ( new_metadata . columns . getDefaults ( ) . count ( col ) ) <nl> throw Exception ( " Newly added column " + col + " has a default expression , so adding " <nl> " expressions that use it to the sorting key is forbidden " , <nl> ErrorCodes : : BAD_ARGUMENTS ) ; <nl> void MergeTreeData : : setProperties ( const StorageInMemoryMetadata & metadata , bool <nl> } <nl> } <nl> <nl> - auto new_sorting_key_syntax = SyntaxAnalyzer ( global_context ) . analyze ( new_sorting_key_expr_list , all_columns ) ; <nl> - auto new_sorting_key_expr = ExpressionAnalyzer ( new_sorting_key_expr_list , new_sorting_key_syntax , global_context ) <nl> - . getActions ( false ) ; <nl> - auto new_sorting_key_sample = <nl> - ExpressionAnalyzer ( new_sorting_key_expr_list , new_sorting_key_syntax , global_context ) <nl> - . getActions ( true ) - > getSampleBlock ( ) ; <nl> - <nl> - checkKeyExpression ( * new_sorting_key_expr , new_sorting_key_sample , " Sorting " ) ; <nl> - <nl> - auto new_primary_key_syntax = SyntaxAnalyzer ( global_context ) . analyze ( new_primary_key_expr_list , all_columns ) ; <nl> - auto new_primary_key_expr = ExpressionAnalyzer ( new_primary_key_expr_list , new_primary_key_syntax , global_context ) <nl> - . getActions ( false ) ; <nl> - <nl> - Block new_primary_key_sample ; <nl> - DataTypes new_primary_key_data_types ; <nl> - for ( size_t i = 0 ; i < primary_key_size ; + + i ) <nl> - { <nl> - const auto & elem = new_sorting_key_sample . getByPosition ( i ) ; <nl> - new_primary_key_sample . insert ( elem ) ; <nl> - new_primary_key_data_types . push_back ( elem . type ) ; <nl> - } <nl> - <nl> - DataTypes new_sorting_key_data_types ; <nl> - for ( size_t i = 0 ; i < sorting_key_size ; + + i ) <nl> + if ( ! new_metadata . secondary_indices . empty ( ) ) <nl> { <nl> - new_sorting_key_data_types . push_back ( new_sorting_key_sample . getByPosition ( i ) . type ) ; <nl> - } <nl> + std : : unordered_set < String > indices_names ; <nl> <nl> - if ( ! metadata . secondary_indices . empty ( ) ) <nl> - { <nl> - std : : set < String > indices_names ; <nl> - <nl> - for ( const auto & index : metadata . secondary_indices ) <nl> + for ( const auto & index : new_metadata . secondary_indices ) <nl> { <nl> <nl> MergeTreeIndexFactory : : instance ( ) . validate ( index , attach ) ; <nl> void MergeTreeData : : setProperties ( const StorageInMemoryMetadata & metadata , bool <nl> } <nl> } <nl> <nl> - if ( ! only_check ) <nl> - { <nl> - setColumns ( std : : move ( metadata . columns ) ) ; <nl> - <nl> - StorageMetadataKeyField new_sorting_key ; <nl> - new_sorting_key . definition_ast = metadata . order_by_ast ; <nl> - new_sorting_key . column_names = std : : move ( new_sorting_key_columns ) ; <nl> - new_sorting_key . expression_list_ast = std : : move ( new_sorting_key_expr_list ) ; <nl> - new_sorting_key . expression = std : : move ( new_sorting_key_expr ) ; <nl> - new_sorting_key . sample_block = std : : move ( new_sorting_key_sample ) ; <nl> - new_sorting_key . data_types = std : : move ( new_sorting_key_data_types ) ; <nl> - setSortingKey ( new_sorting_key ) ; <nl> + checkKeyExpression ( * new_sorting_key . expression , new_sorting_key . sample_block , " Sorting " ) ; <nl> <nl> - StorageMetadataKeyField new_primary_key ; <nl> - new_primary_key . definition_ast = metadata . primary_key_ast ; <nl> - new_primary_key . column_names = std : : move ( new_primary_key_columns ) ; <nl> - new_primary_key . expression_list_ast = std : : move ( new_primary_key_expr_list ) ; <nl> - new_primary_key . expression = std : : move ( new_primary_key_expr ) ; <nl> - new_primary_key . sample_block = std : : move ( new_primary_key_sample ) ; <nl> - new_primary_key . data_types = std : : move ( new_primary_key_data_types ) ; <nl> - setPrimaryKey ( new_primary_key ) ; <nl> + } <nl> <nl> - setSecondaryIndices ( metadata . secondary_indices ) ; <nl> + void MergeTreeData : : setProperties ( const StorageInMemoryMetadata & new_metadata , bool attach ) <nl> + { <nl> + checkProperties ( new_metadata , attach ) ; <nl> <nl> - setConstraints ( metadata . constraints ) ; <nl> - } <nl> + / / / Other parts of metadata initialized is separate methods <nl> + setColumns ( std : : move ( new_metadata . columns ) ) ; <nl> + setSecondaryIndices ( std : : move ( new_metadata . secondary_indices ) ) ; <nl> + setConstraints ( std : : move ( new_metadata . constraints ) ) ; <nl> + setSortingKey ( std : : move ( new_metadata . sorting_key ) ) ; <nl> + setPrimaryKey ( std : : move ( new_metadata . primary_key ) ) ; <nl> } <nl> <nl> namespace <nl> { <nl> <nl> ExpressionActionsPtr getCombinedIndicesExpression ( <nl> - const StorageMetadataKeyField & key , <nl> + const KeyDescription & key , <nl> const IndicesDescription & indices , <nl> const ColumnsDescription & columns , <nl> const Context & context ) <nl> ExpressionActionsPtr MergeTreeData : : getSortingKeyAndSkipIndicesExpression ( ) cons <nl> return getCombinedIndicesExpression ( getSortingKey ( ) , getSecondaryIndices ( ) , getColumns ( ) , global_context ) ; <nl> } <nl> <nl> - ASTPtr MergeTreeData : : extractKeyExpressionList ( const ASTPtr & node ) <nl> - { <nl> - if ( ! node ) <nl> - return std : : make_shared < ASTExpressionList > ( ) ; <nl> - <nl> - const auto * expr_func = node - > as < ASTFunction > ( ) ; <nl> - <nl> - if ( expr_func & & expr_func - > name = = " tuple " ) <nl> - { <nl> - / / / Primary key is specified in tuple , extract its arguments . <nl> - return expr_func - > arguments - > clone ( ) ; <nl> - } <nl> - else <nl> - { <nl> - / / / Primary key consists of one column . <nl> - auto res = std : : make_shared < ASTExpressionList > ( ) ; <nl> - res - > children . push_back ( node ) ; <nl> - return res ; <nl> - } <nl> - } <nl> - <nl> <nl> - void MergeTreeData : : initPartitionKey ( ASTPtr partition_by_ast ) <nl> + void MergeTreeData : : initPartitionKey ( const KeyDescription & new_partition_key ) <nl> { <nl> - StorageMetadataKeyField new_partition_key = StorageMetadataKeyField : : getKeyFromAST ( partition_by_ast , getColumns ( ) , global_context ) ; <nl> - <nl> if ( new_partition_key . expression_list_ast - > children . empty ( ) ) <nl> return ; <nl> <nl> void MergeTreeData : : initPartitionKey ( ASTPtr partition_by_ast ) <nl> } <nl> <nl> <nl> - void MergeTreeData : : setTTLExpressions ( const ColumnsDescription & new_columns , <nl> - const ASTPtr & new_ttl_table_ast , bool only_check ) <nl> + void MergeTreeData : : checkTTLExpressions ( const StorageInMemoryMetadata & new_metadata ) const <nl> { <nl> + auto new_column_ttls = new_metadata . column_ttls_by_name ; <nl> <nl> - auto new_column_ttls_asts = new_columns . getColumnTTLs ( ) ; <nl> - <nl> - TTLColumnsDescription new_column_ttl_by_name = getColumnTTLs ( ) ; <nl> - <nl> - if ( ! new_column_ttls_asts . empty ( ) ) <nl> + if ( ! new_column_ttls . empty ( ) ) <nl> { <nl> NameSet columns_ttl_forbidden ; <nl> <nl> void MergeTreeData : : setTTLExpressions ( const ColumnsDescription & new_columns , <nl> for ( const auto & col : getColumnsRequiredForSortingKey ( ) ) <nl> columns_ttl_forbidden . insert ( col ) ; <nl> <nl> - for ( const auto & [ name , ast ] : new_column_ttls_asts ) <nl> + for ( const auto & [ name , ttl_description ] : new_column_ttls ) <nl> { <nl> if ( columns_ttl_forbidden . count ( name ) ) <nl> throw Exception ( " Trying to set TTL for key column " + name , ErrorCodes : : ILLEGAL_COLUMN ) ; <nl> - else <nl> - { <nl> - auto new_ttl_entry = TTLDescription : : getTTLFromAST ( ast , new_columns , global_context , getPrimaryKey ( ) ) ; <nl> - new_column_ttl_by_name [ name ] = new_ttl_entry ; <nl> - } <nl> } <nl> - if ( ! only_check ) <nl> - setColumnTTLs ( new_column_ttl_by_name ) ; <nl> } <nl> + auto new_table_ttl = new_metadata . table_ttl ; <nl> <nl> - if ( new_ttl_table_ast ) <nl> + if ( new_table_ttl . definition_ast ) <nl> { <nl> - TTLDescriptions update_move_ttl_entries ; <nl> - TTLDescription update_rows_ttl_entry ; <nl> - <nl> - bool seen_delete_ttl = false ; <nl> - for ( const auto & ttl_element_ptr : new_ttl_table_ast - > children ) <nl> + for ( const auto & move_ttl : new_table_ttl . move_ttl ) <nl> { <nl> - const auto * ttl_element = ttl_element_ptr - > as < ASTTTLElement > ( ) ; <nl> - if ( ! ttl_element ) <nl> - throw Exception ( " Unexpected AST element in TTL expression " , ErrorCodes : : UNEXPECTED_AST_STRUCTURE ) ; <nl> - <nl> - if ( ttl_element - > destination_type = = DataDestinationType : : DELETE ) <nl> - { <nl> - if ( seen_delete_ttl ) <nl> - { <nl> - throw Exception ( " More than one DELETE TTL expression is not allowed " , ErrorCodes : : BAD_TTL_EXPRESSION ) ; <nl> - } <nl> - <nl> - update_rows_ttl_entry = TTLDescription : : getTTLFromAST ( ttl_element_ptr , new_columns , global_context , getPrimaryKey ( ) ) ; <nl> - <nl> - seen_delete_ttl = true ; <nl> - } <nl> - else <nl> + if ( ! getDestinationForTTL ( move_ttl ) ) <nl> { <nl> - auto new_ttl_entry = TTLDescription : : getTTLFromAST ( ttl_element_ptr , new_columns , global_context , getPrimaryKey ( ) ) ; <nl> - <nl> - if ( ! getDestinationForTTL ( new_ttl_entry ) ) <nl> - { <nl> - String message ; <nl> - if ( new_ttl_entry . destination_type = = DataDestinationType : : DISK ) <nl> - message = " No such disk " + backQuote ( new_ttl_entry . destination_name ) + " for given storage policy . " ; <nl> - else <nl> - message = " No such volume " + backQuote ( new_ttl_entry . destination_name ) + " for given storage policy . " ; <nl> - throw Exception ( message , ErrorCodes : : BAD_TTL_EXPRESSION ) ; <nl> - } <nl> - <nl> - update_move_ttl_entries . emplace_back ( std : : move ( new_ttl_entry ) ) ; <nl> + String message ; <nl> + if ( move_ttl . destination_type = = DataDestinationType : : DISK ) <nl> + message = " No such disk " + backQuote ( move_ttl . destination_name ) + " for given storage policy . " ; <nl> + else <nl> + message = " No such volume " + backQuote ( move_ttl . destination_name ) + " for given storage policy . " ; <nl> + throw Exception ( message , ErrorCodes : : BAD_TTL_EXPRESSION ) ; <nl> } <nl> } <nl> - <nl> - if ( ! only_check ) <nl> - { <nl> - TTLTableDescription new_table_ttl <nl> - { <nl> - . definition_ast = new_ttl_table_ast , <nl> - . rows_ttl = update_rows_ttl_entry , <nl> - . move_ttl = update_move_ttl_entries , <nl> - } ; <nl> - <nl> - auto move_ttl_entries_lock = std : : lock_guard < std : : mutex > ( move_ttl_entries_mutex ) ; <nl> - setTableTTLs ( new_table_ttl ) ; <nl> - } <nl> } <nl> } <nl> <nl> + / / / Todo replace columns with TTL for columns <nl> + void MergeTreeData : : setTTLExpressions ( const StorageInMemoryMetadata & new_metadata ) <nl> + { <nl> + checkTTLExpressions ( new_metadata ) ; <nl> + setColumnTTLs ( new_metadata . column_ttls_by_name ) ; <nl> + setTableTTLs ( new_metadata . table_ttl ) ; <nl> + } <nl> + <nl> <nl> void MergeTreeData : : checkStoragePolicy ( const StoragePolicyPtr & new_storage_policy ) const <nl> { <nl> bool isMetadataOnlyConversion ( const IDataType * from , const IDataType * to ) <nl> <nl> } <nl> <nl> - void MergeTreeData : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & settings ) <nl> + void MergeTreeData : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & settings ) const <nl> { <nl> / / / Check that needed transformations can be applied to the list of columns without considering type conversions . <nl> - StorageInMemoryMetadata metadata = getInMemoryMetadata ( ) ; <nl> - commands . apply ( metadata , global_context ) ; <nl> - if ( getSecondaryIndices ( ) . empty ( ) & & ! metadata . secondary_indices . empty ( ) & & <nl> + StorageInMemoryMetadata new_metadata = getInMemoryMetadata ( ) ; <nl> + commands . apply ( new_metadata , global_context ) ; <nl> + if ( getSecondaryIndices ( ) . empty ( ) & & ! new_metadata . secondary_indices . empty ( ) & & <nl> ! settings . allow_experimental_data_skipping_indices ) <nl> throw Exception ( " You must set the setting ` allow_experimental_data_skipping_indices ` to 1 " \ <nl> " before using data skipping indices . " , ErrorCodes : : BAD_ARGUMENTS ) ; <nl> void MergeTreeData : : checkAlterIsPossible ( const AlterCommands & commands , const S <nl> } <nl> } <nl> <nl> - setProperties ( metadata , / * only_check = * / true ) ; <nl> + checkProperties ( new_metadata ) ; <nl> <nl> - setTTLExpressions ( metadata . columns , metadata . ttl_for_table_ast , / * only_check = * / true ) ; <nl> + checkTTLExpressions ( new_metadata ) ; <nl> <nl> - if ( settings_ast ) <nl> + if ( hasSettingsChanges ( ) ) <nl> { <nl> - const auto & current_changes = settings_ast - > as < const ASTSetQuery & > ( ) . changes ; <nl> - const auto & new_changes = metadata . settings_ast - > as < const ASTSetQuery & > ( ) . changes ; <nl> + <nl> + const auto current_changes = getSettingsChanges ( ) - > as < const ASTSetQuery & > ( ) . changes ; <nl> + const auto & new_changes = new_metadata . settings_changes - > as < const ASTSetQuery & > ( ) . changes ; <nl> for ( const auto & changed_setting : new_changes ) <nl> { <nl> if ( MergeTreeSettings : : findIndex ( changed_setting . name ) = = MergeTreeSettings : : npos ) <nl> void MergeTreeData : : changeSettings ( <nl> MergeTreeSettings copy = * getSettings ( ) ; <nl> copy . applyChanges ( new_changes ) ; <nl> storage_settings . set ( std : : make_unique < const MergeTreeSettings > ( copy ) ) ; <nl> - settings_ast = new_settings ; <nl> + setSettingsChanges ( new_settings ) ; <nl> } <nl> } <nl> <nl> MergeTreeData : : selectTTLEntryForTTLInfos ( const IMergeTreeDataPart : : TTLInfos & tt <nl> time_t max_max_ttl = 0 ; <nl> TTLDescriptions : : const_iterator best_entry_it ; <nl> <nl> - auto lock = std : : lock_guard ( move_ttl_entries_mutex ) ; <nl> const auto & move_ttl_entries = getMoveTTLs ( ) ; <nl> for ( auto ttl_entry_it = move_ttl_entries . begin ( ) ; ttl_entry_it ! = move_ttl_entries . end ( ) ; + + ttl_entry_it ) <nl> { <nl> mmm a / src / Storages / MergeTree / MergeTreeData . h <nl> ppp b / src / Storages / MergeTree / MergeTreeData . h <nl> <nl> # include < Interpreters / PartLog . h > <nl> # include < Disks / StoragePolicy . h > <nl> # include < Interpreters / Aggregator . h > <nl> + # include < Storages / extractKeyExpressionList . h > <nl> <nl> # include < boost / multi_index_container . hpp > <nl> # include < boost / multi_index / ordered_index . hpp > <nl> class MergeTreeData : public IStorage <nl> / / / attach - whether the existing table is attached or the new table is created . <nl> MergeTreeData ( const StorageID & table_id_ , <nl> const String & relative_data_path_ , <nl> - const StorageInMemoryMetadata & metadata , <nl> + const StorageInMemoryMetadata & metadata_ , <nl> Context & context_ , <nl> const String & date_column_name , <nl> const MergingParams & merging_params_ , <nl> class MergeTreeData : public IStorage <nl> BrokenPartCallback broken_part_callback_ = [ ] ( const String & ) { } ) ; <nl> <nl> <nl> - / / / See comments about methods below in IStorage interface <nl> - StorageInMemoryMetadata getInMemoryMetadata ( ) const override ; <nl> - <nl> StoragePolicyPtr getStoragePolicy ( ) const override ; <nl> <nl> bool supportsPrewhere ( ) const override { return true ; } <nl> class MergeTreeData : public IStorage <nl> / / / - all type conversions can be done . <nl> / / / - columns corresponding to primary key , indices , sign , sampling expression and date are not affected . <nl> / / / If something is wrong , throws an exception . <nl> - void checkAlterIsPossible ( const AlterCommands & commands , const Settings & settings ) override ; <nl> + void checkAlterIsPossible ( const AlterCommands & commands , const Settings & settings ) const override ; <nl> <nl> / / / Change MergeTreeSettings <nl> void changeSettings ( <nl> class MergeTreeData : public IStorage <nl> broken_part_callback ( name ) ; <nl> } <nl> <nl> - / * * Get the key expression AST as an ASTExpressionList . It can be specified <nl> - * in the tuple : ( CounterID , Date ) , or as one column : CounterID . <nl> - * / <nl> - static ASTPtr extractKeyExpressionList ( const ASTPtr & node ) ; <nl> - <nl> + / / / TODO ( alesap ) Duplicate method required for compatibility . <nl> + / / / Must be removed . <nl> + static ASTPtr extractKeyExpressionList ( const ASTPtr & node ) <nl> + { <nl> + return DB : : extractKeyExpressionList ( node ) ; <nl> + } <nl> <nl> / / / Check that the part is not broken and calculate the checksums for it if they are not present . <nl> MutableDataPartPtr loadPartAndFixMetadata ( const VolumePtr & volume , const String & relative_path ) const ; <nl> class MergeTreeData : public IStorage <nl> <nl> std : : optional < TTLDescription > selectTTLEntryForTTLInfos ( const IMergeTreeDataPart : : TTLInfos & ttl_infos , time_t time_of_move ) const ; <nl> <nl> - / / / This mutex is required for background move operations which do not <nl> - / / / obtain global locks . <nl> - / / / TODO ( alesap ) It will be removed after metadata became atomic <nl> - mutable std : : mutex move_ttl_entries_mutex ; <nl> - <nl> / / / Limiting parallel sends per one table , used in DataPartsExchange <nl> std : : atomic_uint current_table_sends { 0 } ; <nl> <nl> class MergeTreeData : public IStorage <nl> friend struct ReplicatedMergeTreeTableMetadata ; <nl> friend class StorageReplicatedMergeTree ; <nl> <nl> - ASTPtr settings_ast ; <nl> - <nl> bool require_part_metadata ; <nl> <nl> String relative_data_path ; <nl> class MergeTreeData : public IStorage <nl> / / / The same for clearOldTemporaryDirectories . <nl> std : : mutex clear_old_temporary_directories_mutex ; <nl> <nl> - void setProperties ( const StorageInMemoryMetadata & metadata , bool only_check = false , bool attach = false ) ; <nl> + void checkProperties ( const StorageInMemoryMetadata & new_metadata , bool attach = false ) const ; <nl> + <nl> + void setProperties ( const StorageInMemoryMetadata & new_metadata , bool attach = false ) ; <nl> <nl> - void initPartitionKey ( ASTPtr partition_by_ast ) ; <nl> + void initPartitionKey ( const KeyDescription & new_partition_key ) ; <nl> <nl> - void setTTLExpressions ( const ColumnsDescription & columns , <nl> - const ASTPtr & new_ttl_table_ast , bool only_check = false ) ; <nl> + void checkTTLExpressions ( const StorageInMemoryMetadata & new_metadata ) const ; <nl> + void setTTLExpressions ( const StorageInMemoryMetadata & new_metadata ) ; <nl> <nl> void checkStoragePolicy ( const StoragePolicyPtr & new_storage_policy ) const ; <nl> <nl> mmm a / src / Storages / MergeTree / StorageFromMergeTreeDataPart . h <nl> ppp b / src / Storages / MergeTree / StorageFromMergeTreeDataPart . h <nl> class StorageFromMergeTreeDataPart final : public ext : : shared_ptr_helper < Storage <nl> return part - > storage . mayBenefitFromIndexForIn ( left_in_operand , query_context ) ; <nl> } <nl> <nl> - StorageInMemoryMetadata getInMemoryMetadata ( ) const override <nl> - { <nl> - return part - > storage . getInMemoryMetadata ( ) ; <nl> - } <nl> - <nl> NamesAndTypesList getVirtuals ( ) const override <nl> { <nl> return part - > storage . getVirtuals ( ) ; <nl> mmm a / src / Storages / MergeTree / registerStorageMergeTree . cpp <nl> ppp b / src / Storages / MergeTree / registerStorageMergeTree . cpp <nl> static StoragePtr create ( const StorageFactory : : Arguments & args ) <nl> + + arg_num ; <nl> } <nl> <nl> + / / / This merging param maybe used as part of sorting key <nl> + std : : optional < String > merging_param_key_arg ; <nl> + <nl> if ( merging_params . mode = = MergeTreeData : : MergingParams : : Collapsing ) <nl> { <nl> if ( ! tryGetIdentifierNameInto ( engine_args [ arg_cnt - 1 ] , merging_params . sign_column ) ) <nl> static StoragePtr create ( const StorageFactory : : Arguments & args ) <nl> ErrorCodes : : BAD_ARGUMENTS ) ; <nl> <nl> - - arg_cnt ; <nl> + / / / Version collapsing is the only engine which add additional column to <nl> + / / / sorting key . <nl> + merging_param_key_arg = merging_params . version_column ; <nl> } <nl> <nl> String date_column_name ; <nl> - ASTPtr partition_by_ast ; <nl> - ASTPtr order_by_ast ; <nl> - ASTPtr primary_key_ast ; <nl> - ASTPtr sample_by_ast ; <nl> - ASTPtr ttl_table_ast ; <nl> - ASTPtr settings_ast ; <nl> - IndicesDescription indices_description ; <nl> - ConstraintsDescription constraints_description ; <nl> + <nl> + StorageInMemoryMetadata metadata ; <nl> + metadata . columns = args . columns ; <nl> <nl> std : : unique_ptr < MergeTreeSettings > storage_settings = std : : make_unique < MergeTreeSettings > ( args . context . getMergeTreeSettings ( ) ) ; <nl> <nl> if ( is_extended_storage_def ) <nl> { <nl> + ASTPtr partition_by_key ; <nl> if ( args . storage_def - > partition_by ) <nl> - partition_by_ast = args . storage_def - > partition_by - > ptr ( ) ; <nl> + partition_by_key = args . storage_def - > partition_by - > ptr ( ) ; <nl> + <nl> + / / / Partition key may be undefined , but despite this we store it ' s empty <nl> + / / / value in partition_key structure . MergeTree checks this case and use <nl> + / / / single default partition with name " all " . <nl> + metadata . partition_key = KeyDescription : : getKeyFromAST ( partition_by_key , metadata . columns , args . context ) ; <nl> <nl> if ( ! args . storage_def - > order_by ) <nl> throw Exception ( " You must provide an ORDER BY expression in the table definition . " <nl> " If you don ' t want this table to be sorted , use ORDER BY tuple ( ) " , <nl> ErrorCodes : : BAD_ARGUMENTS ) ; <nl> <nl> - order_by_ast = args . storage_def - > order_by - > ptr ( ) ; <nl> + / / / Get sorting key from engine arguments . <nl> + / / / <nl> + / / / NOTE : store merging_param_key_arg as additional key column . We do it <nl> + / / / before storage creation . After that storage will just copy this <nl> + / / / column if sorting key will be changed . <nl> + metadata . sorting_key = KeyDescription : : getSortingKeyFromAST ( args . storage_def - > order_by - > ptr ( ) , metadata . columns , args . context , merging_param_key_arg ) ; <nl> <nl> + / / / If primary key explicitely defined , than get it from AST <nl> if ( args . storage_def - > primary_key ) <nl> - primary_key_ast = args . storage_def - > primary_key - > ptr ( ) ; <nl> + { <nl> + metadata . primary_key = KeyDescription : : getKeyFromAST ( args . storage_def - > primary_key - > ptr ( ) , metadata . columns , args . context ) ; <nl> + } <nl> + else / / / Otherwise we copy it from primary key definition <nl> + { <nl> + metadata . primary_key = KeyDescription : : getKeyFromAST ( args . storage_def - > order_by - > ptr ( ) , metadata . columns , args . context ) ; <nl> + / / / and set it ' s definition_ast to nullptr ( so isPrimaryKeyDefined ( ) <nl> + / / / will return false but hasPrimaryKey ( ) will return true . <nl> + metadata . primary_key . definition_ast = nullptr ; <nl> + } <nl> <nl> if ( args . storage_def - > sample_by ) <nl> - sample_by_ast = args . storage_def - > sample_by - > ptr ( ) ; <nl> + metadata . sampling_key = KeyDescription : : getKeyFromAST ( args . storage_def - > sample_by - > ptr ( ) , metadata . columns , args . context ) ; <nl> <nl> if ( args . storage_def - > ttl_table ) <nl> - ttl_table_ast = args . storage_def - > ttl_table - > ptr ( ) ; <nl> - <nl> + metadata . table_ttl = TTLTableDescription : : getTTLForTableFromAST ( <nl> + args . storage_def - > ttl_table - > ptr ( ) , <nl> + metadata . columns , <nl> + args . context , <nl> + metadata . primary_key ) ; <nl> <nl> if ( args . query . columns_list & & args . query . columns_list - > indices ) <nl> for ( auto & index : args . query . columns_list - > indices - > children ) <nl> - indices_description . push_back ( IndexDescription : : getIndexFromAST ( index , args . columns , args . context ) ) ; <nl> + metadata . secondary_indices . push_back ( IndexDescription : : getIndexFromAST ( index , args . columns , args . context ) ) ; <nl> + <nl> + if ( args . query . columns_list & & args . query . columns_list - > constraints ) <nl> + for ( auto & constraint : args . query . columns_list - > constraints - > children ) <nl> + metadata . constraints . constraints . push_back ( constraint ) ; <nl> + <nl> + auto column_ttl_asts = args . columns . getColumnTTLs ( ) ; <nl> + for ( const auto & [ name , ast ] : column_ttl_asts ) <nl> + { <nl> + auto new_ttl_entry = TTLDescription : : getTTLFromAST ( ast , args . columns , args . context , metadata . primary_key ) ; <nl> + metadata . column_ttls_by_name [ name ] = new_ttl_entry ; <nl> + } <nl> <nl> storage_settings - > loadFromQuery ( * args . storage_def ) ; <nl> <nl> if ( args . storage_def - > settings ) <nl> - settings_ast = args . storage_def - > settings - > ptr ( ) ; <nl> + metadata . settings_changes = args . storage_def - > settings - > ptr ( ) ; <nl> } <nl> else <nl> { <nl> static StoragePtr create ( const StorageFactory : : Arguments & args ) <nl> / / / If there is an expression for sampling <nl> if ( arg_cnt - arg_num = = 3 ) <nl> { <nl> - sample_by_ast = engine_args [ arg_num ] ; <nl> + metadata . sampling_key = KeyDescription : : getKeyFromAST ( engine_args [ arg_num ] , metadata . columns , args . context ) ; <nl> + + arg_num ; <nl> } <nl> <nl> - / / / Now only two parameters remain - primary_key , index_granularity . <nl> - order_by_ast = engine_args [ arg_num ] ; <nl> + / / / Get sorting key from engine arguments . <nl> + / / / <nl> + / / / NOTE : store merging_param_key_arg as additional key column . We do it <nl> + / / / before storage creation . After that storage will just copy this <nl> + / / / column if sorting key will be changed . <nl> + metadata . sorting_key = KeyDescription : : getSortingKeyFromAST ( engine_args [ arg_num ] , metadata . columns , args . context , merging_param_key_arg ) ; <nl> + <nl> + / / / In old syntax primary_key always equals to sorting key . <nl> + metadata . primary_key = KeyDescription : : getKeyFromAST ( engine_args [ arg_num ] , metadata . columns , args . context ) ; <nl> + / / / But it ' s not explicitely defined , so we evaluate definition to <nl> + / / / nullptr <nl> + metadata . primary_key . definition_ast = nullptr ; <nl> + <nl> + + arg_num ; <nl> <nl> const auto * ast = engine_args [ arg_num ] - > as < ASTLiteral > ( ) ; <nl> static StoragePtr create ( const StorageFactory : : Arguments & args ) <nl> if ( arg_num ! = arg_cnt ) <nl> throw Exception ( " Wrong number of engine arguments . " , ErrorCodes : : BAD_ARGUMENTS ) ; <nl> <nl> - if ( ! args . attach & & ! indices_description . empty ( ) & & ! args . local_context . getSettingsRef ( ) . allow_experimental_data_skipping_indices ) <nl> + if ( ! args . attach & & ! metadata . secondary_indices . empty ( ) & & ! args . local_context . getSettingsRef ( ) . allow_experimental_data_skipping_indices ) <nl> throw Exception ( " You must set the setting ` allow_experimental_data_skipping_indices ` to 1 " \ <nl> " before using data skipping indices . " , ErrorCodes : : BAD_ARGUMENTS ) ; <nl> <nl> - StorageInMemoryMetadata metadata ( args . columns , indices_description , args . constraints ) ; <nl> - metadata . partition_by_ast = partition_by_ast ; <nl> - metadata . order_by_ast = order_by_ast ; <nl> - metadata . primary_key_ast = primary_key_ast ; <nl> - metadata . ttl_for_table_ast = ttl_table_ast ; <nl> - metadata . sample_by_ast = sample_by_ast ; <nl> - metadata . settings_ast = settings_ast ; <nl> - <nl> if ( replicated ) <nl> return StorageReplicatedMergeTree : : create ( <nl> zookeeper_path , replica_name , args . attach , args . table_id , args . relative_data_path , <nl> new file mode 100644 <nl> index 00000000000 . . 87ba4ce74a9 <nl> mmm / dev / null <nl> ppp b / src / Storages / SelectQueryDescription . cpp <nl> <nl> + # include < Storages / SelectQueryDescription . h > <nl> + <nl> + # include < Parsers / ASTSelectWithUnionQuery . h > <nl> + # include < Parsers / ASTSelectQuery . h > <nl> + # include < Interpreters / getTableExpressions . h > <nl> + # include < Interpreters / AddDefaultDatabaseVisitor . h > <nl> + # include < Interpreters / Context . h > <nl> + <nl> + namespace DB <nl> + { <nl> + <nl> + namespace ErrorCodes <nl> + { <nl> + extern const int QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ; <nl> + extern const int LOGICAL_ERROR ; <nl> + } <nl> + <nl> + SelectQueryDescription : : SelectQueryDescription ( const SelectQueryDescription & other ) <nl> + : select_table_id ( other . select_table_id ) <nl> + , select_query ( other . select_query ? other . select_query - > clone ( ) : nullptr ) <nl> + , inner_query ( other . inner_query ? other . inner_query - > clone ( ) : nullptr ) <nl> + { <nl> + } <nl> + <nl> + SelectQueryDescription & SelectQueryDescription : : SelectQueryDescription : : operator = ( const SelectQueryDescription & other ) <nl> + { <nl> + if ( & other = = this ) <nl> + return * this ; <nl> + <nl> + select_table_id = other . select_table_id ; <nl> + if ( other . select_query ) <nl> + select_query = other . select_query - > clone ( ) ; <nl> + else <nl> + select_query . reset ( ) ; <nl> + <nl> + if ( other . inner_query ) <nl> + inner_query = other . inner_query - > clone ( ) ; <nl> + else <nl> + inner_query . reset ( ) ; <nl> + return * this ; <nl> + } <nl> + <nl> + <nl> + namespace <nl> + { <nl> + <nl> + StorageID extractDependentTableFromSelectQuery ( ASTSelectQuery & query , const Context & context , bool add_default_db = true ) <nl> + { <nl> + if ( add_default_db ) <nl> + { <nl> + AddDefaultDatabaseVisitor visitor ( context . getCurrentDatabase ( ) , nullptr ) ; <nl> + visitor . visit ( query ) ; <nl> + } <nl> + <nl> + if ( auto db_and_table = getDatabaseAndTable ( query , 0 ) ) <nl> + { <nl> + return StorageID ( db_and_table - > database , db_and_table - > table / * , db_and_table - > uuid * / ) ; <nl> + } <nl> + else if ( auto subquery = extractTableExpression ( query , 0 ) ) <nl> + { <nl> + auto * ast_select = subquery - > as < ASTSelectWithUnionQuery > ( ) ; <nl> + if ( ! ast_select ) <nl> + throw Exception ( " Logical error while creating StorageMaterializedView . " <nl> + " Could not retrieve table name from select query . " , <nl> + DB : : ErrorCodes : : LOGICAL_ERROR ) ; <nl> + if ( ast_select - > list_of_selects - > children . size ( ) ! = 1 ) <nl> + throw Exception ( " UNION is not supported for MATERIALIZED VIEW " , <nl> + ErrorCodes : : QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ) ; <nl> + <nl> + auto & inner_query = ast_select - > list_of_selects - > children . at ( 0 ) ; <nl> + <nl> + return extractDependentTableFromSelectQuery ( inner_query - > as < ASTSelectQuery & > ( ) , context , false ) ; <nl> + } <nl> + else <nl> + return StorageID : : createEmpty ( ) ; <nl> + } <nl> + <nl> + <nl> + void checkAllowedQueries ( const ASTSelectQuery & query ) <nl> + { <nl> + if ( query . prewhere ( ) | | query . final ( ) | | query . sampleSize ( ) ) <nl> + throw Exception ( " MATERIALIZED VIEW cannot have PREWHERE , SAMPLE or FINAL . " , DB : : ErrorCodes : : QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ) ; <nl> + <nl> + ASTPtr subquery = extractTableExpression ( query , 0 ) ; <nl> + if ( ! subquery ) <nl> + return ; <nl> + <nl> + if ( const auto * ast_select = subquery - > as < ASTSelectWithUnionQuery > ( ) ) <nl> + { <nl> + if ( ast_select - > list_of_selects - > children . size ( ) ! = 1 ) <nl> + throw Exception ( " UNION is not supported for MATERIALIZED VIEW " , ErrorCodes : : QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ) ; <nl> + <nl> + const auto & inner_query = ast_select - > list_of_selects - > children . at ( 0 ) ; <nl> + <nl> + checkAllowedQueries ( inner_query - > as < ASTSelectQuery & > ( ) ) ; <nl> + } <nl> + } <nl> + <nl> + } <nl> + <nl> + SelectQueryDescription SelectQueryDescription : : getSelectQueryFromASTForMatView ( const ASTPtr & select , const Context & context ) <nl> + { <nl> + auto & new_select = select - > as < ASTSelectWithUnionQuery & > ( ) ; <nl> + <nl> + if ( new_select . list_of_selects - > children . size ( ) ! = 1 ) <nl> + throw Exception ( " UNION is not supported for MATERIALIZED VIEW " , ErrorCodes : : QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ) ; <nl> + <nl> + SelectQueryDescription result ; <nl> + <nl> + result . inner_query = new_select . list_of_selects - > children . at ( 0 ) - > clone ( ) ; <nl> + <nl> + auto & select_query = result . inner_query - > as < ASTSelectQuery & > ( ) ; <nl> + checkAllowedQueries ( select_query ) ; <nl> + result . select_table_id = extractDependentTableFromSelectQuery ( select_query , context ) ; <nl> + result . select_query = select - > clone ( ) ; <nl> + <nl> + return result ; <nl> + } <nl> + <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . ce3ca44c147 <nl> mmm / dev / null <nl> ppp b / src / Storages / SelectQueryDescription . h <nl> <nl> + # pragma once <nl> + <nl> + # include < Interpreters / StorageID . h > <nl> + <nl> + namespace DB <nl> + { <nl> + <nl> + / / / Select query for different view in storages <nl> + struct SelectQueryDescription <nl> + { <nl> + / / / Table id for select query <nl> + StorageID select_table_id = StorageID : : createEmpty ( ) ; <nl> + / / / Select query itself ( ASTSelectWithUnionQuery ) <nl> + ASTPtr select_query ; <nl> + / / / First query from select_query list <nl> + ASTPtr inner_query ; <nl> + <nl> + / / / Parse description from select query for materialized view . Also <nl> + / / / validates query . <nl> + static SelectQueryDescription getSelectQueryFromASTForMatView ( const ASTPtr & select , const Context & context ) ; <nl> + <nl> + SelectQueryDescription ( ) = default ; <nl> + SelectQueryDescription ( const SelectQueryDescription & other ) ; <nl> + SelectQueryDescription & operator = ( const SelectQueryDescription & other ) ; <nl> + } ; <nl> + <nl> + } <nl> mmm a / src / Storages / StorageBuffer . cpp <nl> ppp b / src / Storages / StorageBuffer . cpp <nl> void StorageBuffer : : reschedule ( ) <nl> flush_handle - > scheduleAfter ( std : : min ( min , max ) * 1000 ) ; <nl> } <nl> <nl> - void StorageBuffer : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) <nl> + void StorageBuffer : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) const <nl> { <nl> for ( const auto & command : commands ) <nl> { <nl> void StorageBuffer : : alter ( const AlterCommands & params , const Context & context , <nl> / / / So that no blocks of the old structure remain . <nl> optimize ( { } / * query * / , { } / * partition_id * / , false / * final * / , false / * deduplicate * / , context ) ; <nl> <nl> - StorageInMemoryMetadata metadata = getInMemoryMetadata ( ) ; <nl> - params . apply ( metadata , context ) ; <nl> - DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , metadata ) ; <nl> - setColumns ( std : : move ( metadata . columns ) ) ; <nl> + StorageInMemoryMetadata new_metadata = getInMemoryMetadata ( ) ; <nl> + params . apply ( new_metadata , context ) ; <nl> + DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , new_metadata ) ; <nl> + setColumns ( std : : move ( new_metadata . columns ) ) ; <nl> } <nl> <nl> <nl> mmm a / src / Storages / StorageBuffer . h <nl> ppp b / src / Storages / StorageBuffer . h <nl> friend class BufferBlockOutputStream ; <nl> <nl> bool mayBenefitFromIndexForIn ( const ASTPtr & left_in_operand , const Context & query_context ) const override ; <nl> <nl> - void checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) override ; <nl> + void checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) const override ; <nl> <nl> / / / The structure of the subordinate table is not checked and does not change . <nl> void alter ( const AlterCommands & params , const Context & context , TableStructureWriteLockHolder & table_lock_holder ) override ; <nl> mmm a / src / Storages / StorageDistributed . cpp <nl> ppp b / src / Storages / StorageDistributed . cpp <nl> BlockOutputStreamPtr StorageDistributed : : write ( const ASTPtr & , const Context & c <nl> } <nl> <nl> <nl> - void StorageDistributed : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) <nl> + void StorageDistributed : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) const <nl> { <nl> for ( const auto & command : commands ) <nl> { <nl> void StorageDistributed : : alter ( const AlterCommands & params , const Context & con <nl> auto table_id = getStorageID ( ) ; <nl> <nl> checkAlterIsPossible ( params , context . getSettingsRef ( ) ) ; <nl> - StorageInMemoryMetadata metadata = getInMemoryMetadata ( ) ; <nl> - params . apply ( metadata , context ) ; <nl> - DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , metadata ) ; <nl> - setColumns ( std : : move ( metadata . columns ) ) ; <nl> + StorageInMemoryMetadata new_metadata = getInMemoryMetadata ( ) ; <nl> + params . apply ( new_metadata , context ) ; <nl> + DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , new_metadata ) ; <nl> + setColumns ( std : : move ( new_metadata . columns ) ) ; <nl> } <nl> <nl> <nl> mmm a / src / Storages / StorageDistributed . h <nl> ppp b / src / Storages / StorageDistributed . h <nl> class StorageDistributed final : public ext : : shared_ptr_helper < StorageDistribute <nl> void rename ( const String & new_path_to_table_data , const StorageID & new_table_id ) override ; <nl> void renameOnDisk ( const String & new_path_to_table_data ) ; <nl> <nl> - void checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) override ; <nl> + void checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) const override ; <nl> <nl> / / / in the sub - tables , you need to manually add and delete columns <nl> / / / the structure of the sub - table is not checked <nl> mmm a / src / Storages / StorageInMemoryMetadata . cpp <nl> ppp b / src / Storages / StorageInMemoryMetadata . cpp <nl> <nl> # include < Storages / StorageInMemoryMetadata . h > <nl> <nl> - # include < Functions / IFunction . h > <nl> - # include < Interpreters / ExpressionActions . h > <nl> - # include < Interpreters / ExpressionAnalyzer . h > <nl> - # include < Interpreters / SyntaxAnalyzer . h > <nl> - # include < Parsers / ASTExpressionList . h > <nl> - # include < Parsers / ASTFunction . h > <nl> - # include < Storages / extractKeyExpressionList . h > <nl> - <nl> namespace DB <nl> { <nl> <nl> StorageInMemoryMetadata : : StorageInMemoryMetadata ( const StorageInMemoryMetadata & <nl> : columns ( other . columns ) <nl> , secondary_indices ( other . secondary_indices ) <nl> , constraints ( other . constraints ) <nl> + , partition_key ( other . partition_key ) <nl> + , primary_key ( other . primary_key ) <nl> + , sorting_key ( other . sorting_key ) <nl> + , sampling_key ( other . sampling_key ) <nl> + , column_ttls_by_name ( other . column_ttls_by_name ) <nl> + , table_ttl ( other . table_ttl ) <nl> + , settings_changes ( other . settings_changes ? other . settings_changes - > clone ( ) : nullptr ) <nl> + , select ( other . select ) <nl> { <nl> - if ( other . partition_by_ast ) <nl> - partition_by_ast = other . partition_by_ast - > clone ( ) ; <nl> - if ( other . order_by_ast ) <nl> - order_by_ast = other . order_by_ast - > clone ( ) ; <nl> - if ( other . primary_key_ast ) <nl> - primary_key_ast = other . primary_key_ast - > clone ( ) ; <nl> - if ( other . ttl_for_table_ast ) <nl> - ttl_for_table_ast = other . ttl_for_table_ast - > clone ( ) ; <nl> - if ( other . sample_by_ast ) <nl> - sample_by_ast = other . sample_by_ast - > clone ( ) ; <nl> - if ( other . settings_ast ) <nl> - settings_ast = other . settings_ast - > clone ( ) ; <nl> - if ( other . select ) <nl> - select = other . select - > clone ( ) ; <nl> } <nl> <nl> StorageInMemoryMetadata & StorageInMemoryMetadata : : operator = ( const StorageInMemoryMetadata & other ) <nl> { <nl> - if ( this = = & other ) <nl> + if ( & other = = this ) <nl> return * this ; <nl> <nl> columns = other . columns ; <nl> secondary_indices = other . secondary_indices ; <nl> constraints = other . constraints ; <nl> - <nl> - if ( other . partition_by_ast ) <nl> - partition_by_ast = other . partition_by_ast - > clone ( ) ; <nl> - else <nl> - partition_by_ast . reset ( ) ; <nl> - <nl> - if ( other . order_by_ast ) <nl> - order_by_ast = other . order_by_ast - > clone ( ) ; <nl> - else <nl> - order_by_ast . reset ( ) ; <nl> - <nl> - if ( other . primary_key_ast ) <nl> - primary_key_ast = other . primary_key_ast - > clone ( ) ; <nl> - else <nl> - primary_key_ast . reset ( ) ; <nl> - <nl> - if ( other . ttl_for_table_ast ) <nl> - ttl_for_table_ast = other . ttl_for_table_ast - > clone ( ) ; <nl> - else <nl> - ttl_for_table_ast . reset ( ) ; <nl> - <nl> - if ( other . sample_by_ast ) <nl> - sample_by_ast = other . sample_by_ast - > clone ( ) ; <nl> - else <nl> - sample_by_ast . reset ( ) ; <nl> - <nl> - if ( other . settings_ast ) <nl> - settings_ast = other . settings_ast - > clone ( ) ; <nl> - else <nl> - settings_ast . reset ( ) ; <nl> - <nl> - if ( other . select ) <nl> - select = other . select - > clone ( ) ; <nl> + partition_key = other . partition_key ; <nl> + primary_key = other . primary_key ; <nl> + sorting_key = other . sorting_key ; <nl> + sampling_key = other . sampling_key ; <nl> + column_ttls_by_name = other . column_ttls_by_name ; <nl> + table_ttl = other . table_ttl ; <nl> + if ( other . settings_changes ) <nl> + settings_changes = other . settings_changes - > clone ( ) ; <nl> else <nl> - select . reset ( ) ; <nl> - <nl> + settings_changes . reset ( ) ; <nl> + select = other . select ; <nl> return * this ; <nl> } <nl> <nl> - StorageMetadataKeyField StorageMetadataKeyField : : getKeyFromAST ( const ASTPtr & definition_ast , const ColumnsDescription & columns , const Context & context ) <nl> - { <nl> - StorageMetadataKeyField result ; <nl> - result . definition_ast = definition_ast ; <nl> - result . expression_list_ast = extractKeyExpressionList ( definition_ast ) ; <nl> - <nl> - if ( result . expression_list_ast - > children . empty ( ) ) <nl> - return result ; <nl> - <nl> - const auto & children = result . expression_list_ast - > children ; <nl> - for ( const auto & child : children ) <nl> - result . column_names . emplace_back ( child - > getColumnName ( ) ) ; <nl> - <nl> - { <nl> - auto expr = result . expression_list_ast - > clone ( ) ; <nl> - auto syntax_result = SyntaxAnalyzer ( context ) . analyze ( expr , columns . getAllPhysical ( ) ) ; <nl> - result . expression = ExpressionAnalyzer ( expr , syntax_result , context ) . getActions ( true ) ; <nl> - result . sample_block = result . expression - > getSampleBlock ( ) ; <nl> - } <nl> - <nl> - for ( size_t i = 0 ; i < result . sample_block . columns ( ) ; + + i ) <nl> - result . data_types . emplace_back ( result . sample_block . getByPosition ( i ) . type ) ; <nl> - <nl> - return result ; <nl> - } <nl> <nl> } <nl> mmm a / src / Storages / StorageInMemoryMetadata . h <nl> ppp b / src / Storages / StorageInMemoryMetadata . h <nl> <nl> # pragma once <nl> <nl> + # include < Parsers / IAST_fwd . h > <nl> # include < Storages / ColumnsDescription . h > <nl> - # include < Storages / IndicesDescription . h > <nl> # include < Storages / ConstraintsDescription . h > <nl> - # include < Core / Field . h > <nl> - # include < Parsers / IAST_fwd . h > <nl> + # include < Storages / IndicesDescription . h > <nl> + # include < Storages / KeyDescription . h > <nl> + # include < Storages / TTLDescription . h > <nl> + # include < Storages / SelectQueryDescription . h > <nl> + <nl> <nl> namespace DB <nl> { <nl> struct StorageInMemoryMetadata <nl> / / / Table constraints . Currently supported for MergeTree only . <nl> ConstraintsDescription constraints ; <nl> / / / PARTITION BY expression . Currently supported for MergeTree only . <nl> - ASTPtr partition_by_ast = nullptr ; <nl> + KeyDescription partition_key ; <nl> + / / / PRIMARY KEY expression . If absent , than equal to order_by_ast . <nl> + KeyDescription primary_key ; <nl> / / / ORDER BY expression . Required field for all MergeTree tables <nl> / / / even in old syntax MergeTree ( partition_key , order_by , . . . ) <nl> - ASTPtr order_by_ast = nullptr ; <nl> - / / / PRIMARY KEY expression . If absent , than equal to order_by_ast . <nl> - ASTPtr primary_key_ast = nullptr ; <nl> - / / / TTL expression for whole table . Supported for MergeTree only . <nl> - ASTPtr ttl_for_table_ast = nullptr ; <nl> + KeyDescription sorting_key ; <nl> / / / SAMPLE BY expression . Supported for MergeTree only . <nl> - ASTPtr sample_by_ast = nullptr ; <nl> + KeyDescription sampling_key ; <nl> + / / / Separate ttl expressions for columns <nl> + TTLColumnsDescription column_ttls_by_name ; <nl> + / / / TTL expressions for table ( Move and Rows ) <nl> + TTLTableDescription table_ttl ; <nl> / / / SETTINGS expression . Supported for MergeTree , Buffer and Kafka . <nl> - ASTPtr settings_ast = nullptr ; <nl> - / / / SELECT QUERY . Supported for MaterializedView only . <nl> - ASTPtr select = nullptr ; <nl> + ASTPtr settings_changes ; <nl> + / / / SELECT QUERY . Supported for MaterializedView and View ( have to support LiveView ) . <nl> + SelectQueryDescription select ; <nl> <nl> - StorageInMemoryMetadata ( const StorageInMemoryMetadata & other ) ; <nl> StorageInMemoryMetadata ( ) = default ; <nl> StorageInMemoryMetadata ( const ColumnsDescription & columns_ , const IndicesDescription & secondary_indices_ , const ConstraintsDescription & constraints_ ) ; <nl> <nl> + StorageInMemoryMetadata ( const StorageInMemoryMetadata & other ) ; <nl> StorageInMemoryMetadata & operator = ( const StorageInMemoryMetadata & other ) ; <nl> } ; <nl> <nl> - / / / Common structure for primary , partition and other storage keys <nl> - struct StorageMetadataKeyField <nl> - { <nl> - / / / User defined AST in CREATE / ALTER query . This field may be empty , but key <nl> - / / / can exists because some of them maybe set implicitly ( for example , <nl> - / / / primary key in merge tree can be part of sorting key ) <nl> - ASTPtr definition_ast ; <nl> - <nl> - / / / ASTExpressionList with key fields , example : ( x , toStartOfMonth ( date ) ) ) . <nl> - ASTPtr expression_list_ast ; <nl> - <nl> - / / / Expression from expression_list_ast created by ExpressionAnalyzer . Useful , <nl> - / / / when you need to get required columns for key , example : a , date , b . <nl> - ExpressionActionsPtr expression ; <nl> - <nl> - / / / Sample block with key columns ( names , types , empty column ) <nl> - Block sample_block ; <nl> - <nl> - / / / Column names in key definition , example : x , toStartOfMonth ( date ) , a * b . <nl> - Names column_names ; <nl> - <nl> - / / / Types from sample block ordered in columns order . <nl> - DataTypes data_types ; <nl> - <nl> - / / / Parse key structure from key definition . Requires all columns , available <nl> - / / / in storage . <nl> - static StorageMetadataKeyField getKeyFromAST ( const ASTPtr & definition_ast , const ColumnsDescription & columns , const Context & context ) ; <nl> - } ; <nl> - <nl> } <nl> mmm a / src / Storages / StorageMaterializedView . cpp <nl> ppp b / src / Storages / StorageMaterializedView . cpp <nl> <nl> # include < Storages / AlterCommands . h > <nl> # include < Storages / StorageFactory . h > <nl> # include < Storages / ReadInOrderOptimizer . h > <nl> + # include < Storages / SelectQueryDescription . h > <nl> <nl> # include < Common / typeid_cast . h > <nl> # include < Processors / Sources / SourceFromInputStream . h > <nl> namespace DB <nl> namespace ErrorCodes <nl> { <nl> extern const int NOT_IMPLEMENTED ; <nl> - extern const int LOGICAL_ERROR ; <nl> extern const int INCORRECT_QUERY ; <nl> extern const int QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ; <nl> } <nl> static inline String generateInnerTableName ( const StorageID & view_id ) <nl> return " . inner . " + view_id . getTableName ( ) ; <nl> } <nl> <nl> - static StorageID extractDependentTableFromSelectQuery ( ASTSelectQuery & query , const Context & context , bool add_default_db = true ) <nl> - { <nl> - if ( add_default_db ) <nl> - { <nl> - AddDefaultDatabaseVisitor visitor ( context . getCurrentDatabase ( ) , nullptr ) ; <nl> - visitor . visit ( query ) ; <nl> - } <nl> - <nl> - if ( auto db_and_table = getDatabaseAndTable ( query , 0 ) ) <nl> - { <nl> - return StorageID ( db_and_table - > database , db_and_table - > table / * , db_and_table - > uuid * / ) ; <nl> - } <nl> - else if ( auto subquery = extractTableExpression ( query , 0 ) ) <nl> - { <nl> - auto * ast_select = subquery - > as < ASTSelectWithUnionQuery > ( ) ; <nl> - if ( ! ast_select ) <nl> - throw Exception ( " Logical error while creating StorageMaterializedView . " <nl> - " Could not retrieve table name from select query . " , <nl> - DB : : ErrorCodes : : LOGICAL_ERROR ) ; <nl> - if ( ast_select - > list_of_selects - > children . size ( ) ! = 1 ) <nl> - throw Exception ( " UNION is not supported for MATERIALIZED VIEW " , <nl> - ErrorCodes : : QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ) ; <nl> - <nl> - auto & inner_query = ast_select - > list_of_selects - > children . at ( 0 ) ; <nl> - <nl> - return extractDependentTableFromSelectQuery ( inner_query - > as < ASTSelectQuery & > ( ) , context , false ) ; <nl> - } <nl> - else <nl> - return StorageID : : createEmpty ( ) ; <nl> - } <nl> - <nl> - <nl> - static void checkAllowedQueries ( const ASTSelectQuery & query ) <nl> - { <nl> - if ( query . prewhere ( ) | | query . final ( ) | | query . sampleSize ( ) ) <nl> - throw Exception ( " MATERIALIZED VIEW cannot have PREWHERE , SAMPLE or FINAL . " , DB : : ErrorCodes : : QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ) ; <nl> - <nl> - ASTPtr subquery = extractTableExpression ( query , 0 ) ; <nl> - if ( ! subquery ) <nl> - return ; <nl> - <nl> - if ( const auto * ast_select = subquery - > as < ASTSelectWithUnionQuery > ( ) ) <nl> - { <nl> - if ( ast_select - > list_of_selects - > children . size ( ) ! = 1 ) <nl> - throw Exception ( " UNION is not supported for MATERIALIZED VIEW " , ErrorCodes : : QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ) ; <nl> - <nl> - const auto & inner_query = ast_select - > list_of_selects - > children . at ( 0 ) ; <nl> - <nl> - checkAllowedQueries ( inner_query - > as < ASTSelectQuery & > ( ) ) ; <nl> - } <nl> - } <nl> - <nl> <nl> StorageMaterializedView : : StorageMaterializedView ( <nl> const StorageID & table_id_ , <nl> StorageMaterializedView : : StorageMaterializedView ( <nl> if ( query . select - > list_of_selects - > children . size ( ) ! = 1 ) <nl> throw Exception ( " UNION is not supported for MATERIALIZED VIEW " , ErrorCodes : : QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ) ; <nl> <nl> - select = query . select - > clone ( ) ; <nl> - inner_query = query . select - > list_of_selects - > children . at ( 0 ) ; <nl> - <nl> - auto & select_query = inner_query - > as < ASTSelectQuery & > ( ) ; <nl> - checkAllowedQueries ( select_query ) ; <nl> - <nl> - select_table_id = extractDependentTableFromSelectQuery ( select_query , local_context ) ; <nl> + auto select = SelectQueryDescription : : getSelectQueryFromASTForMatView ( query . select - > clone ( ) , local_context ) ; <nl> + setSelectQuery ( select ) ; <nl> <nl> if ( ! has_inner_table ) <nl> target_table_id = query . to_table_id ; <nl> StorageMaterializedView : : StorageMaterializedView ( <nl> target_table_id = DatabaseCatalog : : instance ( ) . getTable ( { manual_create_query - > database , manual_create_query - > table } , global_context ) - > getStorageID ( ) ; <nl> } <nl> <nl> - if ( ! select_table_id . empty ( ) ) <nl> - DatabaseCatalog : : instance ( ) . addDependency ( select_table_id , getStorageID ( ) ) ; <nl> - } <nl> - <nl> - StorageInMemoryMetadata StorageMaterializedView : : getInMemoryMetadata ( ) const <nl> - { <nl> - StorageInMemoryMetadata result ( getColumns ( ) , getSecondaryIndices ( ) , getConstraints ( ) ) ; <nl> - result . select = getSelectQuery ( ) ; <nl> - return result ; <nl> + if ( ! select . select_table_id . empty ( ) ) <nl> + DatabaseCatalog : : instance ( ) . addDependency ( select . select_table_id , getStorageID ( ) ) ; <nl> } <nl> <nl> QueryProcessingStage : : Enum StorageMaterializedView : : getQueryProcessingStage ( const Context & context , QueryProcessingStage : : Enum to_stage , const ASTPtr & query_ptr ) const <nl> static void executeDropQuery ( ASTDropQuery : : Kind kind , Context & global_context , <nl> void StorageMaterializedView : : drop ( ) <nl> { <nl> auto table_id = getStorageID ( ) ; <nl> - if ( ! select_table_id . empty ( ) ) <nl> - DatabaseCatalog : : instance ( ) . removeDependency ( select_table_id , table_id ) ; <nl> + const auto & select_query = getSelectQuery ( ) ; <nl> + if ( ! select_query . select_table_id . empty ( ) ) <nl> + DatabaseCatalog : : instance ( ) . removeDependency ( select_query . select_table_id , table_id ) ; <nl> <nl> if ( has_inner_table & & tryGetTargetTable ( ) ) <nl> executeDropQuery ( ASTDropQuery : : Kind : : Drop , global_context , target_table_id ) ; <nl> void StorageMaterializedView : : alter ( <nl> { <nl> lockStructureExclusively ( table_lock_holder , context . getCurrentQueryId ( ) , context . getSettingsRef ( ) . lock_acquire_timeout ) ; <nl> auto table_id = getStorageID ( ) ; <nl> - StorageInMemoryMetadata metadata = getInMemoryMetadata ( ) ; <nl> - params . apply ( metadata , context ) ; <nl> + StorageInMemoryMetadata new_metadata = getInMemoryMetadata ( ) ; <nl> + params . apply ( new_metadata , context ) ; <nl> <nl> / / / start modify query <nl> if ( context . getSettingsRef ( ) . allow_experimental_alter_materialized_view_structure ) <nl> { <nl> - auto & new_select = metadata . select - > as < ASTSelectWithUnionQuery & > ( ) ; <nl> - <nl> - if ( new_select . list_of_selects - > children . size ( ) ! = 1 ) <nl> - throw Exception ( " UNION is not supported for MATERIALIZED VIEW " , ErrorCodes : : QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW ) ; <nl> - <nl> - auto & new_inner_query = new_select . list_of_selects - > children . at ( 0 ) ; <nl> - auto & select_query = new_inner_query - > as < ASTSelectQuery & > ( ) ; <nl> - checkAllowedQueries ( select_query ) ; <nl> + const auto & new_select = new_metadata . select ; <nl> + const auto & old_select = getSelectQuery ( ) ; <nl> <nl> - auto new_select_table_id = extractDependentTableFromSelectQuery ( select_query , context ) ; <nl> - DatabaseCatalog : : instance ( ) . updateDependency ( select_table_id , table_id , new_select_table_id , table_id ) ; <nl> + DatabaseCatalog : : instance ( ) . updateDependency ( old_select . select_table_id , table_id , new_select . select_table_id , table_id ) ; <nl> <nl> - select_table_id = new_select_table_id ; <nl> - select = metadata . select ; <nl> - inner_query = new_inner_query ; <nl> + setSelectQuery ( new_select ) ; <nl> } <nl> / / / end modify query <nl> <nl> - DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , metadata ) ; <nl> - setColumns ( std : : move ( metadata . columns ) ) ; <nl> + DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , new_metadata ) ; <nl> + setColumns ( std : : move ( new_metadata . columns ) ) ; <nl> } <nl> <nl> <nl> - void StorageMaterializedView : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & settings ) <nl> + void StorageMaterializedView : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & settings ) const <nl> { <nl> if ( settings . allow_experimental_alter_materialized_view_structure ) <nl> { <nl> void StorageMaterializedView : : renameInMemory ( const StorageID & new_table_id ) <nl> } <nl> <nl> IStorage : : renameInMemory ( new_table_id ) ; <nl> + const auto & select_query = getSelectQuery ( ) ; <nl> / / TODO Actually we don ' t need to update dependency if MV has UUID , but then db and table name will be outdated <nl> - DatabaseCatalog : : instance ( ) . updateDependency ( select_table_id , old_table_id , select_table_id , getStorageID ( ) ) ; <nl> + DatabaseCatalog : : instance ( ) . updateDependency ( select_query . select_table_id , old_table_id , select_query . select_table_id , getStorageID ( ) ) ; <nl> } <nl> <nl> void StorageMaterializedView : : shutdown ( ) <nl> { <nl> + const auto & select_query = getSelectQuery ( ) ; <nl> / / / Make sure the dependency is removed after DETACH TABLE <nl> - if ( ! select_table_id . empty ( ) ) <nl> - DatabaseCatalog : : instance ( ) . removeDependency ( select_table_id , getStorageID ( ) ) ; <nl> + if ( ! select_query . select_table_id . empty ( ) ) <nl> + DatabaseCatalog : : instance ( ) . removeDependency ( select_query . select_table_id , getStorageID ( ) ) ; <nl> } <nl> <nl> StoragePtr StorageMaterializedView : : getTargetTable ( ) const <nl> mmm a / src / Storages / StorageMaterializedView . h <nl> ppp b / src / Storages / StorageMaterializedView . h <nl> class StorageMaterializedView final : public ext : : shared_ptr_helper < StorageMater <nl> std : : string getName ( ) const override { return " MaterializedView " ; } <nl> bool isView ( ) const override { return true ; } <nl> <nl> - ASTPtr getSelectQuery ( ) const { return select - > clone ( ) ; } <nl> - ASTPtr getInnerQuery ( ) const { return inner_query - > clone ( ) ; } <nl> bool hasInnerTable ( ) const { return has_inner_table ; } <nl> <nl> - StorageInMemoryMetadata getInMemoryMetadata ( ) const override ; <nl> - <nl> bool supportsSampling ( ) const override { return getTargetTable ( ) - > supportsSampling ( ) ; } <nl> bool supportsPrewhere ( ) const override { return getTargetTable ( ) - > supportsPrewhere ( ) ; } <nl> bool supportsFinal ( ) const override { return getTargetTable ( ) - > supportsFinal ( ) ; } <nl> class StorageMaterializedView final : public ext : : shared_ptr_helper < StorageMater <nl> <nl> void alter ( const AlterCommands & params , const Context & context , TableStructureWriteLockHolder & table_lock_holder ) override ; <nl> <nl> - void checkAlterIsPossible ( const AlterCommands & commands , const Settings & settings ) override ; <nl> + void checkAlterIsPossible ( const AlterCommands & commands , const Settings & settings ) const override ; <nl> <nl> void alterPartition ( const ASTPtr & query , const PartitionCommands & commands , const Context & context ) override ; <nl> <nl> class StorageMaterializedView final : public ext : : shared_ptr_helper < StorageMater <nl> Strings getDataPaths ( ) const override ; <nl> <nl> private : <nl> - / / / Can be empty if SELECT query doesn ' t contain table <nl> - StorageID select_table_id = StorageID : : createEmpty ( ) ; <nl> / / / Will be initialized in constructor <nl> StorageID target_table_id = StorageID : : createEmpty ( ) ; <nl> <nl> - ASTPtr select ; <nl> - ASTPtr inner_query ; <nl> - <nl> Context & global_context ; <nl> bool has_inner_table = false ; <nl> <nl> mmm a / src / Storages / StorageMerge . cpp <nl> ppp b / src / Storages / StorageMerge . cpp <nl> DatabaseTablesIteratorPtr StorageMerge : : getDatabaseIterator ( const Context & cont <nl> } <nl> <nl> <nl> - void StorageMerge : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) <nl> + void StorageMerge : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) const <nl> { <nl> for ( const auto & command : commands ) <nl> { <nl> mmm a / src / Storages / StorageMerge . h <nl> ppp b / src / Storages / StorageMerge . h <nl> class StorageMerge final : public ext : : shared_ptr_helper < StorageMerge > , public I <nl> size_t max_block_size , <nl> unsigned num_streams ) override ; <nl> <nl> - void checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) override ; <nl> + void checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) const override ; <nl> <nl> / / / you need to add and remove columns in the sub - tables manually <nl> / / / the structure of sub - tables is not checked <nl> mmm a / src / Storages / StorageMergeTree . cpp <nl> ppp b / src / Storages / StorageMergeTree . cpp <nl> namespace ActionLocks <nl> StorageMergeTree : : StorageMergeTree ( <nl> const StorageID & table_id_ , <nl> const String & relative_data_path_ , <nl> - const StorageInMemoryMetadata & metadata , <nl> + const StorageInMemoryMetadata & metadata_ , <nl> bool attach , <nl> Context & context_ , <nl> const String & date_column_name , <nl> StorageMergeTree : : StorageMergeTree ( <nl> : MergeTreeData ( <nl> table_id_ , <nl> relative_data_path_ , <nl> - metadata , <nl> + metadata_ , <nl> context_ , <nl> date_column_name , <nl> merging_params_ , <nl> void StorageMergeTree : : alter ( <nl> { <nl> auto table_id = getStorageID ( ) ; <nl> <nl> - StorageInMemoryMetadata metadata = getInMemoryMetadata ( ) ; <nl> - auto maybe_mutation_commands = commands . getMutationCommands ( metadata , context . getSettingsRef ( ) . materialize_ttl_after_modify , context ) ; <nl> + StorageInMemoryMetadata new_metadata = getInMemoryMetadata ( ) ; <nl> + auto maybe_mutation_commands = commands . getMutationCommands ( new_metadata , context . getSettingsRef ( ) . materialize_ttl_after_modify , context ) ; <nl> String mutation_file_name ; <nl> Int64 mutation_version = - 1 ; <nl> - commands . apply ( metadata , context ) ; <nl> + commands . apply ( new_metadata , context ) ; <nl> <nl> - / / / This alter can be performed at metadata level only <nl> + / / / This alter can be performed at new_metadata level only <nl> if ( commands . isSettingsAlter ( ) ) <nl> { <nl> lockStructureExclusively ( table_lock_holder , context . getCurrentQueryId ( ) , context . getSettingsRef ( ) . lock_acquire_timeout ) ; <nl> <nl> - changeSettings ( metadata . settings_ast , table_lock_holder ) ; <nl> + changeSettings ( new_metadata . settings_changes , table_lock_holder ) ; <nl> <nl> - DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , metadata ) ; <nl> + DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , new_metadata ) ; <nl> } <nl> else <nl> { <nl> void StorageMergeTree : : alter ( <nl> auto merges_block = getActionLock ( ActionLocks : : PartsMerge ) ; <nl> lockStructureExclusively ( table_lock_holder , context . getCurrentQueryId ( ) , context . getSettingsRef ( ) . lock_acquire_timeout ) ; <nl> <nl> - changeSettings ( metadata . settings_ast , table_lock_holder ) ; <nl> + changeSettings ( new_metadata . settings_changes , table_lock_holder ) ; <nl> / / / Reinitialize primary key because primary key column types might have changed . <nl> - setProperties ( metadata ) ; <nl> + setProperties ( new_metadata ) ; <nl> <nl> - setTTLExpressions ( metadata . columns , metadata . ttl_for_table_ast ) ; <nl> + setTTLExpressions ( new_metadata ) ; <nl> <nl> - DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , metadata ) ; <nl> + DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , new_metadata ) ; <nl> <nl> if ( ! maybe_mutation_commands . empty ( ) ) <nl> mutation_version = startMutation ( maybe_mutation_commands , mutation_file_name ) ; <nl> mmm a / src / Storages / StorageNull . cpp <nl> ppp b / src / Storages / StorageNull . cpp <nl> void registerStorageNull ( StorageFactory & factory ) <nl> } ) ; <nl> } <nl> <nl> - void StorageNull : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) <nl> + void StorageNull : : checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) const <nl> { <nl> for ( const auto & command : commands ) <nl> { <nl> void StorageNull : : alter ( <nl> lockStructureExclusively ( table_lock_holder , context . getCurrentQueryId ( ) , context . getSettingsRef ( ) . lock_acquire_timeout ) ; <nl> auto table_id = getStorageID ( ) ; <nl> <nl> - StorageInMemoryMetadata metadata = getInMemoryMetadata ( ) ; <nl> - params . apply ( metadata , context ) ; <nl> - DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , metadata ) ; <nl> - setColumns ( std : : move ( metadata . columns ) ) ; <nl> + StorageInMemoryMetadata new_metadata = getInMemoryMetadata ( ) ; <nl> + params . apply ( new_metadata , context ) ; <nl> + DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( context , table_id , new_metadata ) ; <nl> + setColumns ( std : : move ( new_metadata . columns ) ) ; <nl> } <nl> <nl> } <nl> mmm a / src / Storages / StorageNull . h <nl> ppp b / src / Storages / StorageNull . h <nl> class StorageNull final : public ext : : shared_ptr_helper < StorageNull > , public ISt <nl> return std : : make_shared < NullBlockOutputStream > ( getSampleBlock ( ) ) ; <nl> } <nl> <nl> - void checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) override ; <nl> + void checkAlterIsPossible ( const AlterCommands & commands , const Settings & / * settings * / ) const override ; <nl> <nl> void alter ( const AlterCommands & params , const Context & context , TableStructureWriteLockHolder & table_lock_holder ) override ; <nl> <nl> mmm a / src / Storages / StorageReplicatedMergeTree . cpp <nl> ppp b / src / Storages / StorageReplicatedMergeTree . cpp <nl> StorageReplicatedMergeTree : : StorageReplicatedMergeTree ( <nl> bool attach , <nl> const StorageID & table_id_ , <nl> const String & relative_data_path_ , <nl> - const StorageInMemoryMetadata & metadata , <nl> + const StorageInMemoryMetadata & metadata_ , <nl> Context & context_ , <nl> const String & date_column_name , <nl> const MergingParams & merging_params_ , <nl> StorageReplicatedMergeTree : : StorageReplicatedMergeTree ( <nl> bool has_force_restore_data_flag ) <nl> : MergeTreeData ( table_id_ , <nl> relative_data_path_ , <nl> - metadata , <nl> + metadata_ , <nl> context_ , <nl> date_column_name , <nl> merging_params_ , <nl> bool StorageReplicatedMergeTree : : createTableIfNotExists ( ) <nl> LOG_DEBUG ( log , " Creating table { } " , zookeeper_path ) ; <nl> <nl> / / / We write metadata of table so that the replicas can check table parameters with them . <nl> - String metadata = ReplicatedMergeTreeTableMetadata ( * this ) . toString ( ) ; <nl> + String metadata_str = ReplicatedMergeTreeTableMetadata ( * this ) . toString ( ) ; <nl> <nl> Coordination : : Requests ops ; <nl> ops . emplace_back ( zkutil : : makeCreateRequest ( zookeeper_path , " " , zkutil : : CreateMode : : Persistent ) ) ; <nl> bool StorageReplicatedMergeTree : : createTableIfNotExists ( ) <nl> ops . emplace_back ( zkutil : : makeCreateRequest ( zookeeper_path + " / dropped " , " " , zkutil : : CreateMode : : Persistent ) ) ; <nl> ops . emplace_back ( zkutil : : makeRemoveRequest ( zookeeper_path + " / dropped " , - 1 ) ) ; <nl> <nl> - ops . emplace_back ( zkutil : : makeCreateRequest ( zookeeper_path + " / metadata " , metadata , <nl> + ops . emplace_back ( zkutil : : makeCreateRequest ( zookeeper_path + " / metadata " , metadata_str , <nl> zkutil : : CreateMode : : Persistent ) ) ; <nl> ops . emplace_back ( zkutil : : makeCreateRequest ( zookeeper_path + " / columns " , getColumns ( ) . toString ( ) , <nl> zkutil : : CreateMode : : Persistent ) ) ; <nl> bool StorageReplicatedMergeTree : : createTableIfNotExists ( ) <nl> zkutil : : CreateMode : : Persistent ) ) ; <nl> ops . emplace_back ( zkutil : : makeCreateRequest ( replica_path + " / is_lost " , " 0 " , <nl> zkutil : : CreateMode : : Persistent ) ) ; <nl> - ops . emplace_back ( zkutil : : makeCreateRequest ( replica_path + " / metadata " , metadata , <nl> + ops . emplace_back ( zkutil : : makeCreateRequest ( replica_path + " / metadata " , metadata_str , <nl> zkutil : : CreateMode : : Persistent ) ) ; <nl> ops . emplace_back ( zkutil : : makeCreateRequest ( replica_path + " / columns " , getColumns ( ) . toString ( ) , <nl> zkutil : : CreateMode : : Persistent ) ) ; <nl> void StorageReplicatedMergeTree : : checkTableStructure ( const String & zookeeper_pr <nl> <nl> void StorageReplicatedMergeTree : : setTableStructure ( ColumnsDescription new_columns , const ReplicatedMergeTreeTableMetadata : : Diff & metadata_diff ) <nl> { <nl> - StorageInMemoryMetadata metadata = getInMemoryMetadata ( ) ; <nl> - if ( new_columns ! = metadata . columns ) <nl> - metadata . columns = new_columns ; <nl> + StorageInMemoryMetadata new_metadata = getInMemoryMetadata ( ) ; <nl> + if ( new_columns ! = new_metadata . columns ) <nl> + { <nl> + new_metadata . columns = new_columns ; <nl> + <nl> + new_metadata . column_ttls_by_name . clear ( ) ; <nl> + for ( const auto & [ name , ast ] : new_metadata . columns . getColumnTTLs ( ) ) <nl> + { <nl> + auto new_ttl_entry = TTLDescription : : getTTLFromAST ( ast , new_metadata . columns , global_context , new_metadata . primary_key ) ; <nl> + new_metadata . column_ttls_by_name [ name ] = new_ttl_entry ; <nl> + } <nl> + } <nl> <nl> if ( ! metadata_diff . empty ( ) ) <nl> { <nl> void StorageReplicatedMergeTree : : setTableStructure ( ColumnsDescription new_column <nl> ParserNotEmptyExpressionList parser ( false ) ; <nl> auto new_sorting_key_expr_list = parseQuery ( parser , metadata_diff . new_sorting_key , 0 , DBMS_DEFAULT_MAX_PARSER_DEPTH ) ; <nl> <nl> + ASTPtr order_by_ast ; <nl> if ( new_sorting_key_expr_list - > children . size ( ) = = 1 ) <nl> - metadata . order_by_ast = new_sorting_key_expr_list - > children [ 0 ] ; <nl> + order_by_ast = new_sorting_key_expr_list - > children [ 0 ] ; <nl> else <nl> { <nl> auto tuple = makeASTFunction ( " tuple " ) ; <nl> tuple - > arguments - > children = new_sorting_key_expr_list - > children ; <nl> - metadata . order_by_ast = tuple ; <nl> + order_by_ast = tuple ; <nl> } <nl> + auto & sorting_key = new_metadata . sorting_key ; <nl> + auto & primary_key = new_metadata . primary_key ; <nl> + <nl> + sorting_key . recalculateWithNewAST ( order_by_ast , new_metadata . columns , global_context ) ; <nl> <nl> - if ( ! isPrimaryKeyDefined ( ) ) <nl> + if ( primary_key . definition_ast = = nullptr ) <nl> { <nl> / / / Primary and sorting key become independent after this ALTER so we have to <nl> / / / save the old ORDER BY expression as the new primary key . <nl> - metadata . primary_key_ast = getSortingKeyAST ( ) - > clone ( ) ; <nl> + auto old_sorting_key_ast = getSortingKey ( ) . definition_ast ; <nl> + primary_key = KeyDescription : : getKeyFromAST ( <nl> + old_sorting_key_ast , new_metadata . columns , global_context ) ; <nl> } <nl> } <nl> <nl> if ( metadata_diff . skip_indices_changed ) <nl> - metadata . secondary_indices = IndicesDescription : : parse ( metadata_diff . new_skip_indices , new_columns , global_context ) ; <nl> + new_metadata . secondary_indices = IndicesDescription : : parse ( metadata_diff . new_skip_indices , new_columns , global_context ) ; <nl> <nl> if ( metadata_diff . constraints_changed ) <nl> - metadata . constraints = ConstraintsDescription : : parse ( metadata_diff . new_constraints ) ; <nl> + new_metadata . constraints = ConstraintsDescription : : parse ( metadata_diff . new_constraints ) ; <nl> <nl> if ( metadata_diff . ttl_table_changed ) <nl> { <nl> ParserTTLExpressionList parser ; <nl> - metadata . ttl_for_table_ast = parseQuery ( parser , metadata_diff . new_ttl_table , 0 , DBMS_DEFAULT_MAX_PARSER_DEPTH ) ; <nl> + auto ttl_for_table_ast = parseQuery ( parser , metadata_diff . new_ttl_table , 0 , DBMS_DEFAULT_MAX_PARSER_DEPTH ) ; <nl> + new_metadata . table_ttl = TTLTableDescription : : getTTLForTableFromAST ( ttl_for_table_ast , new_metadata . columns , global_context , new_metadata . primary_key ) ; <nl> } <nl> } <nl> <nl> auto table_id = getStorageID ( ) ; <nl> - DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( global_context , table_id , metadata ) ; <nl> + DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( global_context , table_id , new_metadata ) ; <nl> <nl> / / / Even if the primary / sorting keys didn ' t change we must reinitialize it <nl> / / / because primary key column types might have changed . <nl> - setProperties ( metadata ) ; <nl> - setTTLExpressions ( new_columns , metadata . ttl_for_table_ast ) ; <nl> + setProperties ( new_metadata ) ; <nl> + setTTLExpressions ( new_metadata ) ; <nl> } <nl> <nl> <nl> void StorageReplicatedMergeTree : : alter ( <nl> table_lock_holder , query_context . getCurrentQueryId ( ) , query_context . getSettingsRef ( ) . lock_acquire_timeout ) ; <nl> / / / We don ' t replicate storage_settings_ptr ALTER . It ' s local operation . <nl> / / / Also we don ' t upgrade alter lock to table structure lock . <nl> - StorageInMemoryMetadata metadata = getInMemoryMetadata ( ) ; <nl> - params . apply ( metadata , query_context ) ; <nl> + StorageInMemoryMetadata future_metadata = getInMemoryMetadata ( ) ; <nl> + params . apply ( future_metadata , query_context ) ; <nl> <nl> <nl> - changeSettings ( metadata . settings_ast , table_lock_holder ) ; <nl> + changeSettings ( future_metadata . settings_changes , table_lock_holder ) ; <nl> <nl> - DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( query_context , table_id , metadata ) ; <nl> + DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( query_context , table_id , future_metadata ) ; <nl> return ; <nl> } <nl> <nl> void StorageReplicatedMergeTree : : alter ( <nl> params . apply ( future_metadata , query_context ) ; <nl> <nl> ReplicatedMergeTreeTableMetadata future_metadata_in_zk ( * this ) ; <nl> - if ( ast_to_str ( future_metadata . order_by_ast ) ! = ast_to_str ( current_metadata . order_by_ast ) ) <nl> - future_metadata_in_zk . sorting_key = serializeAST ( * extractKeyExpressionList ( future_metadata . order_by_ast ) ) ; <nl> + if ( ast_to_str ( future_metadata . sorting_key . definition_ast ) ! = ast_to_str ( current_metadata . sorting_key . definition_ast ) ) <nl> + future_metadata_in_zk . sorting_key = serializeAST ( * future_metadata . sorting_key . expression_list_ast ) ; <nl> <nl> - if ( ast_to_str ( future_metadata . ttl_for_table_ast ) ! = ast_to_str ( current_metadata . ttl_for_table_ast ) ) <nl> - future_metadata_in_zk . ttl_table = serializeAST ( * future_metadata . ttl_for_table_ast ) ; <nl> + if ( ast_to_str ( future_metadata . table_ttl . definition_ast ) ! = ast_to_str ( current_metadata . table_ttl . definition_ast ) ) <nl> + future_metadata_in_zk . ttl_table = serializeAST ( * future_metadata . table_ttl . definition_ast ) ; <nl> <nl> String new_indices_str = future_metadata . secondary_indices . toString ( ) ; <nl> if ( new_indices_str ! = current_metadata . secondary_indices . toString ( ) ) <nl> void StorageReplicatedMergeTree : : alter ( <nl> String new_columns_str = future_metadata . columns . toString ( ) ; <nl> ops . emplace_back ( zkutil : : makeSetRequest ( zookeeper_path + " / columns " , new_columns_str , - 1 ) ) ; <nl> <nl> - if ( ast_to_str ( current_metadata . settings_ast ) ! = ast_to_str ( future_metadata . settings_ast ) ) <nl> + if ( ast_to_str ( current_metadata . settings_changes ) ! = ast_to_str ( future_metadata . settings_changes ) ) <nl> { <nl> lockStructureExclusively ( <nl> table_lock_holder , query_context . getCurrentQueryId ( ) , query_context . getSettingsRef ( ) . lock_acquire_timeout ) ; <nl> / / / Just change settings <nl> - current_metadata . settings_ast = future_metadata . settings_ast ; <nl> - changeSettings ( current_metadata . settings_ast , table_lock_holder ) ; <nl> + current_metadata . settings_changes = future_metadata . settings_changes ; <nl> + changeSettings ( current_metadata . settings_changes , table_lock_holder ) ; <nl> DatabaseCatalog : : instance ( ) . getDatabase ( table_id . database_name ) - > alterTable ( query_context , table_id , current_metadata ) ; <nl> } <nl> <nl> mmm a / src / Storages / StorageReplicatedMergeTree . h <nl> ppp b / src / Storages / StorageReplicatedMergeTree . h <nl> class StorageReplicatedMergeTree final : public ext : : shared_ptr_helper < StorageRe <nl> bool attach , <nl> const StorageID & table_id_ , <nl> const String & relative_data_path_ , <nl> - const StorageInMemoryMetadata & metadata , <nl> + const StorageInMemoryMetadata & metadata_ , <nl> Context & context_ , <nl> const String & date_column_name , <nl> const MergingParams & merging_params_ , <nl> mmm a / src / Storages / StorageView . cpp <nl> ppp b / src / Storages / StorageView . cpp <nl> <nl> <nl> # include < Storages / StorageView . h > <nl> # include < Storages / StorageFactory . h > <nl> + # include < Storages / SelectQueryDescription . h > <nl> <nl> # include < Common / typeid_cast . h > <nl> <nl> StorageView : : StorageView ( <nl> if ( ! query . select ) <nl> throw Exception ( " SELECT query is not specified for " + getName ( ) , ErrorCodes : : INCORRECT_QUERY ) ; <nl> <nl> - inner_query = query . select - > ptr ( ) ; <nl> + SelectQueryDescription description ; <nl> + <nl> + description . inner_query = query . select - > ptr ( ) ; <nl> + setSelectQuery ( description ) ; <nl> } <nl> <nl> <nl> Pipes StorageView : : read ( <nl> { <nl> Pipes pipes ; <nl> <nl> - ASTPtr current_inner_query = inner_query ; <nl> + ASTPtr current_inner_query = getSelectQuery ( ) . inner_query ; <nl> + <nl> if ( query_info . view_query ) <nl> { <nl> if ( ! query_info . view_query - > as < ASTSelectWithUnionQuery > ( ) ) <nl> mmm a / src / Storages / StorageView . h <nl> ppp b / src / Storages / StorageView . h <nl> class StorageView final : public ext : : shared_ptr_helper < StorageView > , public ISt <nl> <nl> void replaceWithSubquery ( ASTSelectQuery & select_query , ASTPtr & view_name ) const <nl> { <nl> - replaceWithSubquery ( select_query , inner_query - > clone ( ) , view_name ) ; <nl> + replaceWithSubquery ( select_query , getSelectQuery ( ) . inner_query - > clone ( ) , view_name ) ; <nl> } <nl> <nl> static void replaceWithSubquery ( ASTSelectQuery & outer_query , ASTPtr view_query , ASTPtr & view_name ) ; <nl> static ASTPtr restoreViewName ( ASTSelectQuery & select_query , const ASTPtr & view_name ) ; <nl> <nl> - private : <nl> - ASTPtr inner_query ; <nl> - <nl> protected : <nl> StorageView ( <nl> const StorageID & table_id_ , <nl> mmm a / src / Storages / TTLDescription . cpp <nl> ppp b / src / Storages / TTLDescription . cpp <nl> extern const int BAD_ARGUMENTS ; <nl> extern const int BAD_TTL_EXPRESSION ; <nl> } <nl> <nl> + <nl> + TTLAggregateDescription : : TTLAggregateDescription ( const TTLAggregateDescription & other ) <nl> + : column_name ( other . column_name ) <nl> + , expression_result_column_name ( other . expression_result_column_name ) <nl> + { <nl> + if ( other . expression ) <nl> + expression = std : : make_shared < ExpressionActions > ( * other . expression ) ; <nl> + } <nl> + <nl> + TTLAggregateDescription & TTLAggregateDescription : : operator = ( const TTLAggregateDescription & other ) <nl> + { <nl> + if ( & other = = this ) <nl> + return * this ; <nl> + <nl> + column_name = other . column_name ; <nl> + expression_result_column_name = other . expression_result_column_name ; <nl> + if ( other . expression ) <nl> + expression = std : : make_shared < ExpressionActions > ( * other . expression ) ; <nl> + else <nl> + expression . reset ( ) ; <nl> + return * this ; <nl> + } <nl> + <nl> namespace <nl> { <nl> <nl> void checkTTLExpression ( const ExpressionActionsPtr & ttl_expression , const Strin <nl> <nl> } <nl> <nl> + TTLDescription : : TTLDescription ( const TTLDescription & other ) <nl> + : mode ( other . mode ) <nl> + , expression_ast ( other . expression_ast ? other . expression_ast - > clone ( ) : nullptr ) <nl> + , result_column ( other . result_column ) <nl> + , where_result_column ( other . where_result_column ) <nl> + , group_by_keys ( other . group_by_keys ) <nl> + , set_parts ( other . set_parts ) <nl> + , aggregate_descriptions ( other . aggregate_descriptions ) <nl> + , destination_type ( other . destination_type ) <nl> + , destination_name ( other . destination_name ) <nl> + { <nl> + if ( other . expression ) <nl> + expression = std : : make_shared < ExpressionActions > ( * other . expression ) ; <nl> + <nl> + if ( other . where_expression ) <nl> + where_expression = std : : make_shared < ExpressionActions > ( * other . where_expression ) ; <nl> + } <nl> + <nl> + TTLDescription & TTLDescription : : operator = ( const TTLDescription & other ) <nl> + { <nl> + if ( & other = = this ) <nl> + return * this ; <nl> + <nl> + mode = other . mode ; <nl> + if ( other . expression_ast ) <nl> + expression_ast = other . expression_ast - > clone ( ) ; <nl> + else <nl> + expression_ast . reset ( ) ; <nl> + <nl> + if ( other . expression ) <nl> + expression = std : : make_shared < ExpressionActions > ( * other . expression ) ; <nl> + else <nl> + expression . reset ( ) ; <nl> + <nl> + result_column = other . result_column ; <nl> + if ( other . where_expression ) <nl> + where_expression = std : : make_shared < ExpressionActions > ( * other . where_expression ) ; <nl> + else <nl> + where_expression . reset ( ) ; <nl> + <nl> + where_result_column = other . where_result_column ; <nl> + group_by_keys = other . group_by_keys ; <nl> + set_parts = other . set_parts ; <nl> + aggregate_descriptions = other . aggregate_descriptions ; <nl> + destination_type = other . destination_type ; <nl> + destination_name = other . destination_name ; <nl> + return * this ; <nl> + } <nl> + <nl> TTLDescription TTLDescription : : getTTLFromAST ( <nl> const ASTPtr & definition_ast , <nl> const ColumnsDescription & columns , <nl> const Context & context , <nl> - const StorageMetadataKeyField & primary_key ) <nl> + const KeyDescription & primary_key ) <nl> { <nl> TTLDescription result ; <nl> const auto * ttl_element = definition_ast - > as < ASTTTLElement > ( ) ; <nl> TTLDescription TTLDescription : : getTTLFromAST ( <nl> auto syntax_result = SyntaxAnalyzer ( context ) . analyze ( value , columns . getAllPhysical ( ) , { } , true ) ; <nl> auto expr_analyzer = ExpressionAnalyzer ( value , syntax_result , context ) ; <nl> <nl> - result . set_parts . emplace_back ( TTLAggregateDescription { <nl> - name , value - > getColumnName ( ) , expr_analyzer . getActions ( false ) } ) ; <nl> + TTLAggregateDescription set_part ; <nl> + set_part . column_name = name ; <nl> + set_part . expression_result_column_name = value - > getColumnName ( ) ; <nl> + set_part . expression = expr_analyzer . getActions ( false ) ; <nl> + <nl> + result . set_parts . emplace_back ( set_part ) ; <nl> <nl> for ( const auto & descr : expr_analyzer . getAnalyzedData ( ) . aggregate_descriptions ) <nl> result . aggregate_descriptions . push_back ( descr ) ; <nl> TTLDescription TTLDescription : : getTTLFromAST ( <nl> return result ; <nl> } <nl> <nl> + <nl> + TTLTableDescription TTLTableDescription : : getTTLForTableFromAST ( <nl> + const ASTPtr & definition_ast , <nl> + const ColumnsDescription & columns , <nl> + const Context & context , <nl> + const KeyDescription & primary_key ) <nl> + { <nl> + TTLTableDescription result ; <nl> + if ( ! definition_ast ) <nl> + return result ; <nl> + <nl> + result . definition_ast = definition_ast - > clone ( ) ; <nl> + <nl> + bool seen_delete_ttl = false ; <nl> + for ( const auto & ttl_element_ptr : definition_ast - > children ) <nl> + { <nl> + auto ttl = TTLDescription : : getTTLFromAST ( ttl_element_ptr , columns , context , primary_key ) ; <nl> + if ( ttl . destination_type = = DataDestinationType : : DELETE ) <nl> + { <nl> + if ( seen_delete_ttl ) <nl> + throw Exception ( " More than one DELETE TTL expression is not allowed " , ErrorCodes : : BAD_TTL_EXPRESSION ) ; <nl> + result . rows_ttl = ttl ; <nl> + seen_delete_ttl = true ; <nl> + } <nl> + else <nl> + result . move_ttl . emplace_back ( std : : move ( ttl ) ) ; <nl> + } <nl> + return result ; <nl> + } <nl> + <nl> } <nl> mmm a / src / Storages / TTLDescription . h <nl> ppp b / src / Storages / TTLDescription . h <nl> <nl> # include < Parsers / IAST_fwd . h > <nl> # include < Storages / DataDestinationType . h > <nl> # include < Storages / ColumnsDescription . h > <nl> + # include < Storages / KeyDescription . h > <nl> # include < Interpreters / ExpressionActions . h > <nl> # include < Interpreters / AggregateDescription . h > <nl> - # include < Storages / StorageInMemoryMetadata . h > <nl> # include < Storages / TTLMode . h > <nl> <nl> namespace DB <nl> struct TTLAggregateDescription <nl> <nl> / / / Expressions to calculate the value of assignment expression <nl> ExpressionActionsPtr expression ; <nl> + <nl> + TTLAggregateDescription ( ) = default ; <nl> + TTLAggregateDescription ( const TTLAggregateDescription & other ) ; <nl> + TTLAggregateDescription & operator = ( const TTLAggregateDescription & other ) ; <nl> } ; <nl> <nl> using TTLAggregateDescriptions = std : : vector < TTLAggregateDescription > ; <nl> struct TTLDescription <nl> <nl> / / / Parse TTL structure from definition . Able to parse both column and table <nl> / / / TTLs . <nl> - static TTLDescription getTTLFromAST ( const ASTPtr & definition_ast , const ColumnsDescription & columns , const Context & context , const StorageMetadataKeyField & primary_key ) ; <nl> + static TTLDescription getTTLFromAST ( const ASTPtr & definition_ast , const ColumnsDescription & columns , const Context & context , const KeyDescription & primary_key ) ; <nl> + <nl> + TTLDescription ( ) = default ; <nl> + TTLDescription ( const TTLDescription & other ) ; <nl> + TTLDescription & operator = ( const TTLDescription & other ) ; <nl> } ; <nl> <nl> / / / Mapping from column name to column TTL <nl> struct TTLTableDescription <nl> <nl> / / / Moving data TTL ( to other disks or volumes ) <nl> TTLDescriptions move_ttl ; <nl> + <nl> + static TTLTableDescription getTTLForTableFromAST ( <nl> + const ASTPtr & definition_ast , const ColumnsDescription & columns , const Context & context , const KeyDescription & primary_key ) ; <nl> } ; <nl> <nl> } <nl> mmm a / src / Storages / ya . make <nl> ppp b / src / Storages / ya . make <nl> SRCS ( <nl> VirtualColumnUtils . cpp <nl> extractKeyExpressionList . cpp <nl> TTLDescription . cpp <nl> + KeyDescription . cpp <nl> + SelectQueryDescription . cpp <nl> ) <nl> <nl> END ( ) <nl> mmm a / tests / queries / 0_stateless / 00933_alter_ttl . sql <nl> ppp b / tests / queries / 0_stateless / 00933_alter_ttl . sql <nl> drop table if exists ttl ; <nl> create table ttl ( d Date , a Int ) engine = MergeTree order by tuple ( ) partition by toDayOfMonth ( d ) ; <nl> alter table ttl modify column a Int ttl d + interval 1 day ; <nl> desc table ttl ; <nl> - alter table ttl modify column d Int ttl d + interval 1 day ; - - { serverError 524 } <nl> + alter table ttl modify column d Int ttl d + interval 1 day ; - - { serverError 43 } <nl> + alter table ttl modify column d DateTime ttl d + interval 1 day ; - - { serverError 524 } <nl> <nl> drop table if exists ttl ; <nl> mmm a / tests / queries / 0_stateless / 01213_alter_rename_primary_key_zookeeper . sql <nl> ppp b / tests / queries / 0_stateless / 01213_alter_rename_primary_key_zookeeper . sql <nl> INSERT INTO table_for_rename_pk SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number <nl> <nl> SELECT key1 , value1 FROM table_for_rename_pk WHERE key1 = 1 AND key2 = 1 AND key3 = 1 ; <nl> <nl> - ALTER TABLE table_for_rename_pk RENAME COLUMN key1 TO renamed_key1 ; - - { serverError 524 } <nl> + ALTER TABLE table_for_rename_pk RENAME COLUMN key1 TO renamed_key1 ; - - { serverError 47 } <nl> <nl> - ALTER TABLE table_for_rename_pk RENAME COLUMN key3 TO renamed_key3 ; - - { serverError 524 } <nl> + ALTER TABLE table_for_rename_pk RENAME COLUMN key3 TO renamed_key3 ; - - { serverError 47 } <nl> <nl> - ALTER TABLE table_for_rename_pk RENAME COLUMN key2 TO renamed_key2 ; - - { serverError 524 } <nl> + ALTER TABLE table_for_rename_pk RENAME COLUMN key2 TO renamed_key2 ; - - { serverError 47 } <nl> <nl> DROP TABLE IF EXISTS table_for_rename_pk NO DELAY ; <nl> SELECT sleep ( 1 ) FORMAT Null ; <nl> PRIMARY KEY ( key1 , key2 ) ; <nl> <nl> INSERT INTO table_for_rename_with_primary_key SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number , number , number , toString ( number ) , toString ( number ) from numbers ( 9 ) ; <nl> <nl> - ALTER TABLE table_for_rename_with_primary_key RENAME COLUMN key1 TO renamed_key1 ; - - { serverError 524 } <nl> + ALTER TABLE table_for_rename_with_primary_key RENAME COLUMN key1 TO renamed_key1 ; - - { serverError 47 } <nl> <nl> - ALTER TABLE table_for_rename_with_primary_key RENAME COLUMN key2 TO renamed_key2 ; - - { serverError 524 } <nl> + ALTER TABLE table_for_rename_with_primary_key RENAME COLUMN key2 TO renamed_key2 ; - - { serverError 47 } <nl> <nl> - ALTER TABLE table_for_rename_with_primary_key RENAME COLUMN key3 TO renamed_key3 ; - - { serverError 524 } <nl> + ALTER TABLE table_for_rename_with_primary_key RENAME COLUMN key3 TO renamed_key3 ; - - { serverError 47 } <nl> <nl> ALTER TABLE table_for_rename_with_primary_key RENAME COLUMN value1 TO renamed_value1 ; - - { serverError 524 } <nl> <nl> mmm a / tests / queries / 0_stateless / 01277_alter_rename_column_constraint . sql <nl> ppp b / tests / queries / 0_stateless / 01277_alter_rename_column_constraint . sql <nl> PARTITION BY date <nl> ORDER BY key ; <nl> <nl> INSERT INTO table_for_rename SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number , toString ( number ) , toString ( number + 1 ) , toString ( number + 2 ) from numbers ( 9 ) ; <nl> - INSERT INTO table_for_rename SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number , toString ( number ) , toString ( number + 1 ) , toString ( number ) from numbers ( 9 ) ; ; - - { serverError 469 } <nl> + INSERT INTO table_for_rename SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number , toString ( number ) , toString ( number + 1 ) , toString ( number ) from numbers ( 9 ) ; - - { serverError 469 } <nl> <nl> SELECT * FROM table_for_rename ORDER BY key ; <nl> <nl> SELECT * FROM table_for_rename ORDER BY key ; <nl> <nl> SELECT ' - - insert after rename - - ' ; <nl> INSERT INTO table_for_rename SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number , toString ( number ) , toString ( number + 1 ) , toString ( number + 2 ) from numbers ( 10 , 10 ) ; <nl> - INSERT INTO table_for_rename SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number , toString ( number ) , toString ( number + 1 ) , toString ( number ) from numbers ( 10 , 10 ) ; ; - - { serverError 469 } <nl> + INSERT INTO table_for_rename SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number , toString ( number ) , toString ( number + 1 ) , toString ( number ) from numbers ( 10 , 10 ) ; - - { serverError 469 } <nl> SELECT * FROM table_for_rename ORDER BY key ; <nl> <nl> SELECT ' - - rename columns back - - ' ; <nl> SELECT * FROM table_for_rename ORDER BY key ; <nl> <nl> SELECT ' - - insert after rename column - - ' ; <nl> INSERT INTO table_for_rename SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number , toString ( number ) , toString ( number + 1 ) , toString ( number + 2 ) from numbers ( 20 , 10 ) ; <nl> - INSERT INTO table_for_rename SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number , toString ( number ) , toString ( number ) , toString ( number + 2 ) from numbers ( 20 , 10 ) ; ; - - { serverError 469 } <nl> + INSERT INTO table_for_rename SELECT toDate ( ' 2019 - 10 - 01 ' ) + number % 3 , number , toString ( number ) , toString ( number ) , toString ( number + 2 ) from numbers ( 20 , 10 ) ; - - { serverError 469 } <nl> SELECT * FROM table_for_rename ORDER BY key ; <nl> <nl> DROP TABLE IF EXISTS table_for_rename ; <nl>
Merge pull request from ClickHouse / consistent_metadata4
ClickHouse/ClickHouse
362aaf138599938d83c03d3b6069d7aa8964004b
2020-06-16T10:28:22Z
mmm a / modules / core / src / convert . cpp <nl> ppp b / modules / core / src / convert . cpp <nl> static BinaryFunc cvtTab [ ] [ 8 ] = <nl> { <nl> ( BinaryFunc ) cvt8u , ( BinaryFunc ) GET_OPTIMIZED ( cvt8s8u ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt16u8u ) , <nl> ( BinaryFunc ) GET_OPTIMIZED ( cvt16s8u ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt32s8u ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt32f8u ) , <nl> - ( BinaryFunc ) cvt64f8u , 0 <nl> + ( BinaryFunc ) GET_OPTIMIZED ( cvt64f8u ) , 0 <nl> } , <nl> { <nl> ( BinaryFunc ) GET_OPTIMIZED ( cvt8u8s ) , ( BinaryFunc ) cvt8u , ( BinaryFunc ) GET_OPTIMIZED ( cvt16u8s ) , <nl> ( BinaryFunc ) GET_OPTIMIZED ( cvt16s8s ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt32s8s ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt32f8s ) , <nl> - ( BinaryFunc ) cvt64f8s , 0 <nl> + ( BinaryFunc ) GET_OPTIMIZED ( cvt64f8s ) , 0 <nl> } , <nl> { <nl> ( BinaryFunc ) GET_OPTIMIZED ( cvt8u16u ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt8s16u ) , ( BinaryFunc ) cvt16u , <nl> ( BinaryFunc ) GET_OPTIMIZED ( cvt16s16u ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt32s16u ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt32f16u ) , <nl> - ( BinaryFunc ) cvt64f16u , 0 <nl> + ( BinaryFunc ) GET_OPTIMIZED ( cvt64f16u ) , 0 <nl> } , <nl> { <nl> ( BinaryFunc ) GET_OPTIMIZED ( cvt8u16s ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt8s16s ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt16u16s ) , <nl> ( BinaryFunc ) cvt16u , ( BinaryFunc ) GET_OPTIMIZED ( cvt32s16s ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt32f16s ) , <nl> - ( BinaryFunc ) cvt64f16s , 0 <nl> + ( BinaryFunc ) GET_OPTIMIZED ( cvt64f16s ) , 0 <nl> } , <nl> { <nl> ( BinaryFunc ) GET_OPTIMIZED ( cvt8u32s ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt8s32s ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt16u32s ) , <nl> ( BinaryFunc ) GET_OPTIMIZED ( cvt16s32s ) , ( BinaryFunc ) cvt32s , ( BinaryFunc ) GET_OPTIMIZED ( cvt32f32s ) , <nl> - ( BinaryFunc ) cvt64f32s , 0 <nl> + ( BinaryFunc ) GET_OPTIMIZED ( cvt64f32s ) , 0 <nl> } , <nl> { <nl> ( BinaryFunc ) GET_OPTIMIZED ( cvt8u32f ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt8s32f ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt16u32f ) , <nl> ( BinaryFunc ) GET_OPTIMIZED ( cvt16s32f ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt32s32f ) , ( BinaryFunc ) cvt32s , <nl> - ( BinaryFunc ) cvt64f32f , 0 <nl> + ( BinaryFunc ) GET_OPTIMIZED ( cvt64f32f ) , 0 <nl> } , <nl> { <nl> - ( BinaryFunc ) cvt8u64f , ( BinaryFunc ) cvt8s64f , ( BinaryFunc ) cvt16u64f , <nl> - ( BinaryFunc ) cvt16s64f , ( BinaryFunc ) cvt32s64f , ( BinaryFunc ) cvt32f64f , <nl> + ( BinaryFunc ) GET_OPTIMIZED ( cvt8u64f ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt8s64f ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt16u64f ) , <nl> + ( BinaryFunc ) GET_OPTIMIZED ( cvt16s64f ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt32s64f ) , ( BinaryFunc ) GET_OPTIMIZED ( cvt32f64f ) , <nl> ( BinaryFunc ) cvt64s , 0 <nl> } , <nl> { <nl>
More Tegra versions of convertTo
opencv/opencv
c6e9e9418a06bbab719cec13e50a81a9a0035e3c
2012-03-22T05:27:30Z
mmm a / modules / objdetect / include / opencv2 / objdetect / objdetect . hpp <nl> ppp b / modules / objdetect / include / opencv2 / objdetect / objdetect . hpp <nl> class CV_EXPORTS PlanarObjectDetector <nl> class CV_EXPORTS DOTDetector <nl> { <nl> public : <nl> - struct TrainParams <nl> + struct CV_EXPORTS TrainParams <nl> { <nl> enum { BIN_COUNT = 7 } ; <nl> static double BIN_RANGE ( ) { return 180 . 0 / BIN_COUNT ; } <nl> class CV_EXPORTS DOTDetector <nl> float minRatio ; <nl> } ; <nl> <nl> - struct DetectParams <nl> + struct CV_EXPORTS DetectParams <nl> { <nl> DetectParams ( ) ; <nl> DetectParams ( float minRatio , int minRegionSize , int maxRegionSize , int regionSizeStep , <nl> mmm a / samples / cpp / letter_recog . cpp <nl> ppp b / samples / cpp / letter_recog . cpp <nl> <nl> # include " opencv2 / ml / ml . hpp " <nl> <nl> # include < cstdio > <nl> + # include < vector > <nl> / * <nl> <nl> * / <nl> int build_svm_classifier ( char * data_filename ) <nl> svm . train ( & train_data , train_resp , 0 , 0 , param ) ; <nl> <nl> / / classification <nl> - float _sample [ var_count * ( nsamples_all - ntrain_samples ) ] ; <nl> - CvMat sample = cvMat ( nsamples_all - ntrain_samples , 16 , CV_32FC1 , _sample ) ; <nl> - float true_results [ nsamples_all - ntrain_samples ] ; <nl> + std : : vector < float > _sample ( var_count * ( nsamples_all - ntrain_samples ) ) ; <nl> + CvMat sample = cvMat ( nsamples_all - ntrain_samples , 16 , CV_32FC1 , & _sample [ 0 ] ) ; <nl> + std : : vector < float > true_results ( nsamples_all - ntrain_samples ) ; <nl> for ( int j = ntrain_samples ; j < nsamples_all ; j + + ) <nl> { <nl> float * s = data - > data . fl + j * var_count ; <nl> int build_svm_classifier ( char * data_filename ) <nl> CvMat * result = cvCreateMat ( 1 , nsamples_all - ntrain_samples , CV_32FC1 ) ; <nl> <nl> printf ( " Classification ( may take a few minutes ) . . . \ n " ) ; <nl> - ( int ) svm . predict ( & sample , result ) ; <nl> + svm . predict ( & sample , result ) ; <nl> <nl> int true_resp = 0 ; <nl> for ( int i = 0 ; i < nsamples_all - ntrain_samples ; i + + ) <nl>
made the samples compile on Windows
opencv/opencv
9702b5ef8a56d52c9fe218bab3c328ac3a631435
2011-04-29T12:41:30Z
mmm a / test / cctest / test - factory . cc <nl> ppp b / test / cctest / test - factory . cc <nl> namespace v8 { <nl> namespace internal { <nl> namespace test_factory { <nl> <nl> - namespace { <nl> - <nl> - constexpr int kInstructionSize = 10 * MB ; <nl> - <nl> - size_t NearHeapLimitCallback ( void * raw_bool , size_t current_heap_limit , <nl> - size_t initial_heap_limit ) { <nl> - bool * oom_triggered = static_cast < bool * > ( raw_bool ) ; <nl> - * oom_triggered = true ; <nl> - return kInstructionSize * 2 ; <nl> - } <nl> - <nl> - class SetupIsolateWithSmallHeap { <nl> - public : <nl> - SetupIsolateWithSmallHeap ( ) { <nl> - FLAG_max_old_space_size = kInstructionSize / MB / 2 ; / / In MB . <nl> - v8 : : Isolate : : CreateParams create_params ; <nl> - create_params . array_buffer_allocator = CcTest : : array_buffer_allocator ( ) ; <nl> - isolate_ = reinterpret_cast < Isolate * > ( v8 : : Isolate : : New ( create_params ) ) ; <nl> - isolate_ - > heap ( ) - > AddNearHeapLimitCallback ( NearHeapLimitCallback , <nl> - & oom_triggered_ ) ; <nl> - } <nl> - <nl> - ~ SetupIsolateWithSmallHeap ( ) { <nl> - reinterpret_cast < v8 : : Isolate * > ( isolate_ ) - > Dispose ( ) ; <nl> - } <nl> - <nl> - Isolate * isolate ( ) { return isolate_ ; } <nl> - bool oom_triggered ( ) const { return oom_triggered_ ; } <nl> - <nl> - private : <nl> - Isolate * isolate_ ; <nl> - bool oom_triggered_ = false ; <nl> - } ; <nl> - <nl> - } / / namespace <nl> - <nl> TEST ( Factory_CodeBuilder ) { <nl> - Isolate * isolate = CcTest : : i_isolate ( ) ; <nl> - HandleScope scope ( isolate ) ; <nl> + LocalContext env ; <nl> + v8 : : Isolate * isolate = env - > GetIsolate ( ) ; <nl> + Isolate * i_isolate = reinterpret_cast < Isolate * > ( isolate ) ; <nl> + HandleScope scope ( i_isolate ) ; <nl> <nl> / / Create a big function that ends up in CODE_LO_SPACE . <nl> const int instruction_size = kMaxRegularHeapObjectSize + 1 ; <nl> TEST ( Factory_CodeBuilder ) { <nl> desc . unwinding_info_size = 0 ; <nl> desc . origin = nullptr ; <nl> Handle < Code > code = <nl> - Factory : : CodeBuilder ( isolate , desc , Code : : WASM_FUNCTION ) . Build ( ) ; <nl> + Factory : : CodeBuilder ( i_isolate , desc , Code : : WASM_FUNCTION ) . Build ( ) ; <nl> <nl> - CHECK ( isolate - > heap ( ) - > InSpace ( * code , CODE_LO_SPACE ) ) ; <nl> + CHECK ( i_isolate - > heap ( ) - > InSpace ( * code , CODE_LO_SPACE ) ) ; <nl> # if VERIFY_HEAP <nl> - code - > ObjectVerify ( isolate ) ; <nl> + code - > ObjectVerify ( i_isolate ) ; <nl> # endif <nl> } <nl> <nl> - UNINITIALIZED_TEST ( Factory_CodeBuilder_BuildOOM ) { <nl> - SetupIsolateWithSmallHeap isolate_scope ; <nl> - HandleScope scope ( isolate_scope . isolate ( ) ) ; <nl> - std : : unique_ptr < byte [ ] > instructions ( new byte [ kInstructionSize ] ) ; <nl> - CodeDesc desc ; <nl> - desc . instr_size = kInstructionSize ; <nl> - desc . buffer = instructions . get ( ) ; <nl> - <nl> - const Handle < Code > code = <nl> - Factory : : CodeBuilder ( isolate_scope . isolate ( ) , desc , Code : : WASM_FUNCTION ) <nl> - . Build ( ) ; <nl> - <nl> - CHECK ( ! code . is_null ( ) ) ; <nl> - CHECK ( isolate_scope . oom_triggered ( ) ) ; <nl> - } <nl> - <nl> - UNINITIALIZED_TEST ( Factory_CodeBuilder_TryBuildOOM ) { <nl> - SetupIsolateWithSmallHeap isolate_scope ; <nl> - HandleScope scope ( isolate_scope . isolate ( ) ) ; <nl> - std : : unique_ptr < byte [ ] > instructions ( new byte [ kInstructionSize ] ) ; <nl> - CodeDesc desc ; <nl> - desc . instr_size = kInstructionSize ; <nl> - desc . buffer = instructions . get ( ) ; <nl> - <nl> - const MaybeHandle < Code > code = <nl> - Factory : : CodeBuilder ( isolate_scope . isolate ( ) , desc , Code : : WASM_FUNCTION ) <nl> - . TryBuild ( ) ; <nl> - <nl> - CHECK ( code . is_null ( ) ) ; <nl> - CHECK ( ! isolate_scope . oom_triggered ( ) ) ; <nl> - } <nl> - <nl> } / / namespace test_factory <nl> } / / namespace internal <nl> } / / namespace v8 <nl>
Revert " [ heap ] Add tests to CodeBuilder Build and TryBuild "
v8/v8
ff8f5fd714a9d25810f068ad35027a19875c6c45
2019-05-10T07:47:16Z
mmm a / dbms / src / DataStreams / CheckConstraintsBlockOutputStream . h <nl> ppp b / dbms / src / DataStreams / CheckConstraintsBlockOutputStream . h <nl> class CheckConstraintsBlockOutputStream : public IBlockOutputStream <nl> CheckConstraintsBlockOutputStream ( <nl> const BlockOutputStreamPtr & output_ , <nl> const Block & header_ , <nl> - const ConstraintsDescription & constraints_ , <nl> - const Context & context_ ) <nl> + const ConstraintsDescription & constraints_ ) <nl> : output ( output_ ) , <nl> header ( header_ ) , <nl> constraints ( constraints_ ) , <nl> - expressions ( constraints_ . getExpressions ( context_ , header . getNamesAndTypesList ( ) ) ) , <nl> - context ( context_ ) <nl> + expressions ( constraints_ . getExpressions ( context_ , header . getNamesAndTypesList ( ) ) ) <nl> { } <nl> <nl> Block getHeader ( ) const override { return header ; } <nl> class CheckConstraintsBlockOutputStream : public IBlockOutputStream <nl> Block header ; <nl> const ConstraintsDescription constraints ; <nl> const ConstraintsExpressions expressions ; <nl> - const Context & context ; <nl> } ; <nl> } <nl> mmm a / dbms / src / Interpreters / InterpreterInsertQuery . cpp <nl> ppp b / dbms / src / Interpreters / InterpreterInsertQuery . cpp <nl> BlockIO InterpreterInsertQuery : : execute ( ) <nl> out = std : : make_shared < AddingDefaultBlockOutputStream > ( <nl> out , query_sample_block , table - > getSampleBlock ( ) , table - > getColumns ( ) . getDefaults ( ) , context ) ; <nl> <nl> - out = std : : make_shared < CheckConstraintsBlockOutputStream > ( <nl> - out , query_sample_block , table - > getConstraints ( ) , context ) ; <nl> + out = std : : make_shared < CheckConstraintsBlockOutputStream > ( out , query_sample_block , table - > getConstraints ( ) ) ; <nl> <nl> auto out_wrapper = std : : make_shared < CountingBlockOutputStream > ( out ) ; <nl> out_wrapper - > setProcessListElement ( context . getProcessListElement ( ) ) ; <nl>
Removed context from CheckConstraintsBlockOutputStream
ClickHouse/ClickHouse
d1492fc05d534034d1a0ed1322a9e86f1020cc62
2019-05-19T07:17:06Z
new file mode 100644 <nl> index 00000000000 . . e69de29bb2d <nl> new file mode 100644 <nl> index 00000000000 . . 7d8d64bb78b <nl> mmm / dev / null <nl> ppp b / dbms / tests / integration / test_distributed_format / configs / remote_servers . xml <nl> <nl> + < yandex > <nl> + < remote_servers > <nl> + < test_cluster > <nl> + < shard > <nl> + < replica > <nl> + < host > not_existing < / host > <nl> + < port > 9000 < / port > <nl> + < / replica > <nl> + < / shard > <nl> + < / test_cluster > <nl> + < / remote_servers > <nl> + < / yandex > <nl> new file mode 100644 <nl> index 00000000000 . . 2bcc8ab8063 <nl> mmm / dev / null <nl> ppp b / dbms / tests / integration / test_distributed_format / test . py <nl> <nl> + import time <nl> + import pytest <nl> + <nl> + from helpers . cluster import ClickHouseCluster <nl> + from multiprocessing . dummy import Pool <nl> + from helpers . client import QueryRuntimeException , QueryTimeoutExceedException <nl> + <nl> + from helpers . test_tools import assert_eq_with_retry <nl> + <nl> + <nl> + cluster = ClickHouseCluster ( __file__ ) <nl> + node = cluster . add_instance ( ' node ' , config_dir = " configs " , main_configs = [ ' configs / remote_servers . xml ' ] ) <nl> + <nl> + <nl> + @ pytest . fixture ( scope = " module " ) <nl> + def started_cluster ( ) : <nl> + try : <nl> + cluster . start ( ) <nl> + yield cluster <nl> + <nl> + finally : <nl> + cluster . shutdown ( ) <nl> + <nl> + <nl> + def test_single_file ( started_cluster ) : <nl> + node . query ( " create table distr_1 ( x UInt64 , s String ) engine = Distributed ( ' test_cluster ' , database , table ) " ) <nl> + node . query ( " insert into distr_1 values ( 1 , ' a ' ) , ( 2 , ' bb ' ) , ( 3 , ' ccc ' ) " ) <nl> + <nl> + query = " select * from file ( ' / var / lib / clickhouse / data / default / distr_1 / default @ not_existing : 9000 / 1 . bin ' , ' Distributed ' ) " <nl> + out = node . exec_in_container ( [ ' / usr / bin / clickhouse ' , ' local ' , ' - - stacktrace ' , ' - q ' , query ] ) <nl> + <nl> + assert out = = ' 1 \ ta \ n2 \ tbb \ n3 \ tccc \ n ' <nl> + <nl> + query = " create table t ( dummy UInt32 ) engine = File ( ' Distributed ' , ' / var / lib / clickhouse / data / default / distr_1 / default @ not_existing : 9000 / 1 . bin ' ) ; " \ <nl> + " select * from t " <nl> + out = node . exec_in_container ( [ ' / usr / bin / clickhouse ' , ' local ' , ' - - stacktrace ' , ' - q ' , query ] ) <nl> + <nl> + assert out = = ' 1 \ ta \ n2 \ tbb \ n3 \ tccc \ n ' <nl> + <nl> + node . query ( " drop table distr_1 " ) <nl> + <nl> + <nl> + def test_two_files ( started_cluster ) : <nl> + node . query ( " create table distr_2 ( x UInt64 , s String ) engine = Distributed ( ' test_cluster ' , database , table ) " ) <nl> + node . query ( " insert into distr_2 values ( 0 , ' _ ' ) , ( 1 , ' a ' ) " ) <nl> + node . query ( " insert into distr_2 values ( 2 , ' bb ' ) , ( 3 , ' ccc ' ) " ) <nl> + <nl> + query = " select * from file ( ' / var / lib / clickhouse / data / default / distr_2 / default @ not_existing : 9000 / { 1 , 2 , 3 , 4 } . bin ' , ' Distributed ' ) order by x " <nl> + out = node . exec_in_container ( [ ' / usr / bin / clickhouse ' , ' local ' , ' - - stacktrace ' , ' - q ' , query ] ) <nl> + <nl> + assert out = = ' 0 \ t_ \ n1 \ ta \ n2 \ tbb \ n3 \ tccc \ n ' <nl> + <nl> + query = " create table t ( dummy UInt32 ) engine = File ( ' Distributed ' , ' / var / lib / clickhouse / data / default / distr_2 / default @ not_existing : 9000 / { 1 , 2 , 3 , 4 } . bin ' ) ; " \ <nl> + " select * from t order by x " <nl> + out = node . exec_in_container ( [ ' / usr / bin / clickhouse ' , ' local ' , ' - - stacktrace ' , ' - q ' , query ] ) <nl> + <nl> + assert out = = ' 0 \ t_ \ n1 \ ta \ n2 \ tbb \ n3 \ tccc \ n ' <nl> + <nl> + node . query ( " drop table distr_2 " ) <nl>
Added tests
ClickHouse/ClickHouse
e4933eb6c6f3ade6d58778ab3e0ee4ac92c27a5b
2020-01-05T19:36:14Z
mmm a / modules / core / src / ocl . cpp <nl> ppp b / modules / core / src / ocl . cpp <nl> void traceOpenCLCheck ( cl_int status , const char * message ) <nl> CV_OCL_TRACE_CHECK_RESULT ( check_result , msg ) ; \ <nl> if ( check_result ! = CL_SUCCESS ) \ <nl> { \ <nl> - if ( 0 ) { const char * msg_ = ( msg ) ; CV_UNUSED ( msg_ ) ; / * ensure const char * type ( cv : : String without c_str ( ) ) * / } \ <nl> + static_assert ( std : : is_convertible < decltype ( msg ) , const char * > : : value , " msg of CV_OCL_CHECK_RESULT must be const char * " ) ; \ <nl> cv : : String error_msg = CV_OCL_API_ERROR_MSG ( check_result , msg ) ; \ <nl> CV_Error ( Error : : OpenCLApiCallError , error_msg ) ; \ <nl> } \ <nl> void traceOpenCLCheck ( cl_int status , const char * message ) <nl> CV_OCL_TRACE_CHECK_RESULT ( check_result , msg ) ; \ <nl> if ( check_result ! = CL_SUCCESS & & isRaiseError ( ) ) \ <nl> { \ <nl> - if ( 0 ) { const char * msg_ = ( msg ) ; CV_UNUSED ( msg_ ) ; / * ensure const char * type ( cv : : String without c_str ( ) ) * / } \ <nl> + static_assert ( std : : is_convertible < decltype ( msg ) , const char * > : : value , " msg of CV_OCL_DBG_CHECK_RESULT must be const char * " ) ; \ <nl> cv : : String error_msg = CV_OCL_API_ERROR_MSG ( check_result , msg ) ; \ <nl> CV_Error ( Error : : OpenCLApiCallError , error_msg ) ; \ <nl> } \ <nl>
Merge pull request from mgehre : fix_dangling_pointer
opencv/opencv
47007224445af3dce8dadb11174df14d81fd5a34
2019-08-21T11:38:36Z
mmm a / src / core / iomgr / tcp_client_posix . c <nl> ppp b / src / core / iomgr / tcp_client_posix . c <nl> static int prepare_socket ( const struct sockaddr * addr , int fd ) { <nl> return 0 ; <nl> } <nl> <nl> - static void on_alarm ( void * acp , int success ) { <nl> + static void tc_on_alarm ( void * acp , int success ) { <nl> int done ; <nl> async_connect * ac = acp ; <nl> gpr_mu_lock ( & ac - > mu ) ; <nl> - if ( ac - > fd ! = NULL & & success ) { <nl> + if ( ac - > fd ! = NULL ) { <nl> grpc_fd_shutdown ( ac - > fd ) ; <nl> } <nl> done = ( - - ac - > refs = = 0 ) ; <nl> static void on_writable ( void * acp , int success ) { <nl> } else { <nl> grpc_pollset_set_del_fd ( ac - > interested_parties , ac - > fd ) ; <nl> ep = grpc_tcp_create ( ac - > fd , GRPC_TCP_DEFAULT_READ_SLICE_SIZE ) ; <nl> + ac - > fd = NULL ; <nl> goto finish ; <nl> } <nl> } else { <nl> static void on_writable ( void * acp , int success ) { <nl> abort ( ) ; <nl> <nl> finish : <nl> - if ( ep = = NULL ) { <nl> + if ( ac - > fd ! = NULL ) { <nl> grpc_pollset_set_del_fd ( ac - > interested_parties , ac - > fd ) ; <nl> grpc_fd_orphan ( ac - > fd , NULL , " tcp_client_orphan " ) ; <nl> - } else { <nl> ac - > fd = NULL ; <nl> } <nl> done = ( - - ac - > refs = = 0 ) ; <nl> void grpc_tcp_client_connect ( void ( * cb ) ( void * arg , grpc_endpoint * ep ) , <nl> ac - > write_closure . cb_arg = ac ; <nl> <nl> gpr_mu_lock ( & ac - > mu ) ; <nl> - grpc_alarm_init ( & ac - > alarm , deadline , on_alarm , ac , <nl> + grpc_alarm_init ( & ac - > alarm , deadline , tc_on_alarm , ac , <nl> gpr_now ( GPR_CLOCK_REALTIME ) ) ; <nl> grpc_fd_notify_on_write ( ac - > fd , & ac - > write_closure ) ; <nl> gpr_mu_unlock ( & ac - > mu ) ; <nl>
Correct alarm handling
grpc/grpc
286ca4be4dbb39ab992586b51819cd066e127124
2015-07-18T00:19:56Z
mmm a / tools / bindings - generator <nl> ppp b / tools / bindings - generator <nl> @ @ - 1 + 1 @ @ <nl> - Subproject commit e3c5ee837f6ad572ad2578340f015eb1acabaa13 <nl> + Subproject commit 716d9156b845173f14e38fae10a76c54a11b64ef <nl>
issue : Updating submodule of bindings - generator .
cocos2d/cocos2d-x
73c167d1b27a28e70a5f86ee0d1c8ccbd2340cf0
2013-06-20T06:56:33Z
mmm a / tensorflow / stream_executor / cuda / cublas_stub . cc <nl> ppp b / tensorflow / stream_executor / cuda / cublas_stub . cc <nl> typedef enum { } cublasMath_t ; <nl> <nl> # if CUDA_VERSION < 10000 <nl> # include " tensorflow / stream_executor / cuda / cublas_9_0 . inc " <nl> - # elif CUDA_VERSION = = 10000 <nl> + # elif CUDA_VERSION < 10010 <nl> # include " tensorflow / stream_executor / cuda / cublas_10_0 . inc " <nl> - # elif CUDA_VERSION = = 10010 <nl> + # elif CUDA_VERSION < 10020 <nl> # include " tensorflow / stream_executor / cuda / cublas_10_1 . inc " <nl> - # elif CUDA_VERSION = = 10020 <nl> + # elif CUDA_VERSION < 11000 <nl> # include " tensorflow / stream_executor / cuda / cublas_10_2 . inc " <nl> - # elif CUBLAS_VER_MAJOR = = 11 & & CUBLAS_VER_MINOR = = 0 <nl> - # include " tensorflow / stream_executor / cuda / cublas_11_0 . inc " <nl> # else <nl> - # error " We have no wrapper for this version . " <nl> + # include " tensorflow / stream_executor / cuda / cublas_11_0 . inc " <nl> # endif <nl> mmm a / tensorflow / stream_executor / cuda / cuda_stub . cc <nl> ppp b / tensorflow / stream_executor / cuda / cuda_stub . cc <nl> typedef void ( CUDA_CB * CUhostFn ) ( void * userData ) ; <nl> <nl> # if CUDA_VERSION < 10000 <nl> # include " tensorflow / stream_executor / cuda / cuda_9_0 . inc " <nl> - # elif CUDA_VERSION = = 10000 <nl> + # elif CUDA_VERSION < 10010 <nl> # include " tensorflow / stream_executor / cuda / cuda_10_0 . inc " <nl> - # elif CUDA_VERSION < = 10010 <nl> + # elif CUDA_VERSION < 10020 <nl> # include " tensorflow / stream_executor / cuda / cuda_10_1 . inc " <nl> - # elif CUDA_VERSION < = 10020 <nl> + # elif CUDA_VERSION < 11000 <nl> # include " tensorflow / stream_executor / cuda / cuda_10_2 . inc " <nl> - # elif CUDA_VERSION < = 11000 <nl> - # include " tensorflow / stream_executor / cuda / cuda_11_0 . inc " <nl> # else <nl> - # error " We have no wrapper for this version . " <nl> + # include " tensorflow / stream_executor / cuda / cuda_11_0 . inc " <nl> # endif <nl> mmm a / tensorflow / stream_executor / cuda / cudart_stub . cc <nl> ppp b / tensorflow / stream_executor / cuda / cudart_stub . cc <nl> cudaError_t GetSymbolNotFoundError ( ) { <nl> / / A bunch of new symbols were introduced in version 10 <nl> # if CUDART_VERSION < 10000 <nl> # include " tensorflow / stream_executor / cuda / cuda_runtime_9_0 . inc " <nl> - # elif CUDART_VERSION = = 10000 <nl> + # elif CUDART_VERSION < 10010 <nl> # include " tensorflow / stream_executor / cuda / cuda_runtime_10_0 . inc " <nl> - # elif CUDART_VERSION = = 10010 <nl> + # elif CUDART_VERSION < 10020 <nl> # include " tensorflow / stream_executor / cuda / cuda_runtime_10_1 . inc " <nl> - # elif CUDART_VERSION = = 10020 <nl> + # elif CUDART_VERSION < 11000 <nl> # include " tensorflow / stream_executor / cuda / cuda_runtime_10_2 . inc " <nl> - # elif CUDART_VERSION = = 11000 <nl> - # include " tensorflow / stream_executor / cuda / cuda_runtime_11_0 . inc " <nl> # else <nl> - # error " We have no wrapper for this version . " <nl> + # include " tensorflow / stream_executor / cuda / cuda_runtime_11_0 . inc " <nl> # endif <nl> # undef __dv <nl> # undef __CUDA_DEPRECATED <nl> mmm a / tensorflow / stream_executor / cuda / cusolver_stub . cc <nl> ppp b / tensorflow / stream_executor / cuda / cusolver_stub . cc <nl> cusolverStatus_t GetSymbolNotFoundError ( ) { <nl> <nl> # if CUDA_VERSION < 10000 <nl> # include " tensorflow / stream_executor / cuda / cusolver_dense_9_0 . inc " <nl> - # elif CUDA_VERSION = = 10000 <nl> + # elif CUDA_VERSION < 10010 <nl> # include " tensorflow / stream_executor / cuda / cusolver_dense_10_0 . inc " <nl> - # elif CUDA_VERSION = = 10010 <nl> + # elif CUDA_VERSION < 10020 <nl> # include " tensorflow / stream_executor / cuda / cusolver_dense_10_1 . inc " <nl> - # elif CUDA_VERSION = = 10020 <nl> + # elif CUDA_VERSION < 11000 <nl> # include " tensorflow / stream_executor / cuda / cusolver_dense_10_2 . inc " <nl> - # elif CUDA_VERSION = = 11000 <nl> - # include " tensorflow / stream_executor / cuda / cusolver_dense_11_0 . inc " <nl> # else <nl> - # error " We don ' t have a wrapper for this version . " <nl> + # include " tensorflow / stream_executor / cuda / cusolver_dense_11_0 . inc " <nl> # endif <nl> mmm a / tensorflow / stream_executor / cuda / cusparse_stub . cc <nl> ppp b / tensorflow / stream_executor / cuda / cusparse_stub . cc <nl> cusparseStatus_t GetSymbolNotFoundError ( ) { <nl> <nl> # if CUDA_VERSION < 10000 <nl> # include " tensorflow / stream_executor / cuda / cusparse_9_0 . inc " <nl> - # elif CUDA_VERSION = = 10000 <nl> + # elif CUDA_VERSION < 10010 <nl> # include " tensorflow / stream_executor / cuda / cusparse_10_0 . inc " <nl> - # elif CUDA_VERSION = = 10010 <nl> + # elif CUDA_VERSION < 10020 <nl> # include " tensorflow / stream_executor / cuda / cusparse_10_1 . inc " <nl> - # elif CUDA_VERSION = = 10020 <nl> + # elif CUDA_VERSION < 11000 <nl> # include " tensorflow / stream_executor / cuda / cusparse_10_2 . inc " <nl> - # elif CUSPARSE_VER_MAJOR = = 11 & & CUSPARSE_VER_MINOR = = 0 <nl> - # include " tensorflow / stream_executor / cuda / cusparse_11_0 . inc " <nl> # else <nl> - # error " We don ' t have a wrapper for this version . " <nl> + # include " tensorflow / stream_executor / cuda / cusparse_11_0 . inc " <nl> # endif <nl>
Merge pull request from nluehr : stub_cleanup
tensorflow/tensorflow
d5163e15c21874fddb03fedaf2cc6316a590f490
2020-06-17T23:21:58Z
mmm a / tensorflow / compiler / mlir / tools / kernel_gen / kernel_creator . cc <nl> ppp b / tensorflow / compiler / mlir / tools / kernel_gen / kernel_creator . cc <nl> Status LowerGPUToLLVM ( mlir : : ModuleOp module , bool gpu_binary_only , <nl> if ( ! gpu_binary_only ) { <nl> pm . addPass ( mlir : : kernel_gen : : tf_framework : : <nl> createTestTFFrameworkLegalizeToLLVMPass ( ) ) ; <nl> - pm . addPass ( mlir : : createGpuToLLVMConversionPass ( gpu_binary_attr_name ) ) ; <nl> pm . addPass ( mlir : : createCanonicalizerPass ( ) ) ; <nl> pm . addPass ( mlir : : createCSEPass ( ) ) ; <nl> } <nl> mmm a / tensorflow / compiler / mlir / tools / kernel_gen / transforms / BUILD <nl> ppp b / tensorflow / compiler / mlir / tools / kernel_gen / transforms / BUILD <nl> cc_library ( <nl> " / / tensorflow / compiler / mlir / tools / kernel_gen / ir : tf_framework_ops " , <nl> " @ llvm - project / / llvm : Support " , <nl> " @ llvm - project / / mlir : GPUDialect " , <nl> + " @ llvm - project / / mlir : GPUToGPURuntimeTransforms " , <nl> " @ llvm - project / / mlir : IR " , <nl> " @ llvm - project / / mlir : LLVMDialect " , <nl> " @ llvm - project / / mlir : LLVMTransforms " , <nl> mmm a / tensorflow / compiler / mlir / tools / kernel_gen / transforms / tf_framework_legalize_to_llvm_pass . cc <nl> ppp b / tensorflow / compiler / mlir / tools / kernel_gen / transforms / tf_framework_legalize_to_llvm_pass . cc <nl> See the License for the specific language governing permissions and <nl> limitations under the License . <nl> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * / <nl> <nl> + # include " mlir / Conversion / GPUCommon / GPUCommonPass . h " / / from @ llvm - project <nl> # include " mlir / Conversion / StandardToLLVM / ConvertStandardToLLVM . h " / / from @ llvm - project <nl> # include " mlir / Conversion / StandardToLLVM / ConvertStandardToLLVMPass . h " / / from @ llvm - project <nl> # include " mlir / Dialect / GPU / GPUDialect . h " / / from @ llvm - project <nl> class TestTFFrameworkToLLVMPass <nl> OwningRewritePatternList patterns ; <nl> populateStdToLLVMConversionPatterns ( type_converter , patterns ) ; <nl> PopulateTFFrameworkToLLVMConversionPatterns ( & type_converter , & patterns ) ; <nl> + populateGpuToLLVMConversionPatterns ( type_converter , patterns , " gpu . binary " ) ; <nl> lmhlo : : PopulateLhloToLLVMConversionPatterns ( & type_converter , & patterns ) ; <nl> <nl> / / Set target . <nl> ConversionTarget target ( getContext ( ) ) ; <nl> target . addLegalDialect < LLVM : : LLVMDialect > ( ) ; <nl> - target . addLegalDialect < gpu : : GPUDialect > ( ) ; <nl> - target . addIllegalDialect < tf_framework : : TFFrameworkDialect > ( ) ; <nl> + target <nl> + . addIllegalDialect < gpu : : GPUDialect , tf_framework : : TFFrameworkDialect > ( ) ; <nl> target . addIllegalOp < LLVM : : DialectCastOp > ( ) ; <nl> <nl> if ( failed ( applyPartialConversion ( m , target , patterns ) ) ) { <nl>
[ MLIR ] [ KERNEL_GEN ] Add patterns for GPU - > LLVM lowering to TFFramework - > LLVM pass .
tensorflow/tensorflow
50a56bb54c109a758365e16e3c38e6ace8905b85
2020-09-09T17:04:30Z
mmm a / BUILD . gn <nl> ppp b / BUILD . gn <nl> v8_source_set ( " v8_base_without_compiler " ) { <nl> " src / objects / js - date - time - format - inl . h " , <nl> " src / objects / js - date - time - format . cc " , <nl> " src / objects / js - date - time - format . h " , <nl> + " src / objects / js - display - names - inl . h " , <nl> + " src / objects / js - display - names . cc " , <nl> + " src / objects / js - display - names . h " , <nl> " src / objects / js - generator - inl . h " , <nl> " src / objects / js - generator . h " , <nl> " src / objects / js - list - format - inl . h " , <nl> v8_source_set ( " v8_base_without_compiler " ) { <nl> " src / objects / js - date - time - format - inl . h " , <nl> " src / objects / js - date - time - format . cc " , <nl> " src / objects / js - date - time - format . h " , <nl> + " src / objects / js - display - names - inl . h " , <nl> + " src / objects / js - display - names . cc " , <nl> + " src / objects / js - display - names . h " , <nl> " src / objects / js - list - format - inl . h " , <nl> " src / objects / js - list - format . cc " , <nl> " src / objects / js - list - format . h " , <nl> mmm a / include / v8 . h <nl> ppp b / include / v8 . h <nl> class V8_EXPORT Isolate { <nl> kRegExpMatchAllWithNonGlobalRegExp = 78 , <nl> kRegExpExecCalledOnSlowRegExp = 79 , <nl> kRegExpReplaceCalledOnSlowRegExp = 80 , <nl> + kDisplayNames = 81 , <nl> <nl> / / If you add new values here , you ' ll also need to update Chromium ' s : <nl> / / web_feature . mojom , use_counter_callback . cc , and enums . xml . V8 changes to <nl> mmm a / src / builtins / builtins - definitions . h <nl> ppp b / src / builtins / builtins - definitions . h <nl> namespace internal { <nl> CPP ( DateTimeFormatPrototypeResolvedOptions ) \ <nl> / * ecma402 # sec - intl . datetimeformat . supportedlocalesof * / \ <nl> CPP ( DateTimeFormatSupportedLocalesOf ) \ <nl> + / * ecma402 # sec - Intl . DisplayNames * / \ <nl> + CPP ( DisplayNamesConstructor ) \ <nl> + / * ecma402 # sec - Intl . DisplayNames . prototype . of * / \ <nl> + CPP ( DisplayNamesPrototypeOf ) \ <nl> + / * ecma402 # sec - Intl . DisplayNames . prototype . resolvedOptions * / \ <nl> + CPP ( DisplayNamesPrototypeResolvedOptions ) \ <nl> + / * ecma402 # sec - Intl . DisplayNames . supportedLocalesOf * / \ <nl> + CPP ( DisplayNamesSupportedLocalesOf ) \ <nl> / * ecma402 # sec - intl . getcanonicallocales * / \ <nl> CPP ( IntlGetCanonicalLocales ) \ <nl> / * ecma402 # sec - intl - listformat - constructor * / \ <nl> mmm a / src / builtins / builtins - intl . cc <nl> ppp b / src / builtins / builtins - intl . cc <nl> <nl> # include " src / objects / js - break - iterator - inl . h " <nl> # include " src / objects / js - collator - inl . h " <nl> # include " src / objects / js - date - time - format - inl . h " <nl> + # include " src / objects / js - display - names - inl . h " <nl> # include " src / objects / js - list - format - inl . h " <nl> # include " src / objects / js - locale - inl . h " <nl> # include " src / objects / js - number - format - inl . h " <nl> Object CallOrConstructConstructor ( BuiltinArguments args , Isolate * isolate , <nl> } <nl> } / / namespace <nl> <nl> + / / Intl . DisplayNames <nl> + <nl> + BUILTIN ( DisplayNamesConstructor ) { <nl> + HandleScope scope ( isolate ) ; <nl> + <nl> + return DisallowCallConstructor < JSDisplayNames > ( <nl> + args , isolate , v8 : : Isolate : : UseCounterFeature : : kDisplayNames , <nl> + " Intl . DisplayNames " ) ; <nl> + } <nl> + <nl> + BUILTIN ( DisplayNamesPrototypeResolvedOptions ) { <nl> + HandleScope scope ( isolate ) ; <nl> + CHECK_RECEIVER ( JSDisplayNames , holder , <nl> + " Intl . DisplayNames . prototype . resolvedOptions " ) ; <nl> + return * JSDisplayNames : : ResolvedOptions ( isolate , holder ) ; <nl> + } <nl> + <nl> + BUILTIN ( DisplayNamesSupportedLocalesOf ) { <nl> + HandleScope scope ( isolate ) ; <nl> + Handle < Object > locales = args . atOrUndefined ( isolate , 1 ) ; <nl> + Handle < Object > options = args . atOrUndefined ( isolate , 2 ) ; <nl> + <nl> + RETURN_RESULT_OR_FAILURE ( <nl> + isolate , Intl : : SupportedLocalesOf ( <nl> + isolate , " Intl . DisplayNames . supportedLocalesOf " , <nl> + JSDisplayNames : : GetAvailableLocales ( ) , locales , options ) ) ; <nl> + } <nl> + <nl> + BUILTIN ( DisplayNamesPrototypeOf ) { <nl> + HandleScope scope ( isolate ) ; <nl> + CHECK_RECEIVER ( JSDisplayNames , holder , " Intl . DisplayNames . prototype . of " ) ; <nl> + Handle < Object > code_obj = args . atOrUndefined ( isolate , 1 ) ; <nl> + <nl> + RETURN_RESULT_OR_FAILURE ( isolate , <nl> + JSDisplayNames : : Of ( isolate , holder , code_obj ) ) ; <nl> + } <nl> + <nl> + / / Intl . NumberFormat <nl> + <nl> BUILTIN ( NumberFormatConstructor ) { <nl> HandleScope scope ( isolate ) ; <nl> <nl> mmm a / src / compiler / code - assembler . h <nl> ppp b / src / compiler / code - assembler . h <nl> class JSAsyncGeneratorObject ; <nl> class JSCollator ; <nl> class JSCollection ; <nl> class JSDateTimeFormat ; <nl> + class JSDisplayNames ; <nl> class JSListFormat ; <nl> class JSLocale ; <nl> class JSNumberFormat ; <nl> mmm a / src / compiler / types . cc <nl> ppp b / src / compiler / types . cc <nl> Type : : bitset BitsetType : : Lub ( const MapRefLike & map ) { <nl> case JS_V8_BREAK_ITERATOR_TYPE : <nl> case JS_COLLATOR_TYPE : <nl> case JS_DATE_TIME_FORMAT_TYPE : <nl> + case JS_DISPLAY_NAMES_TYPE : <nl> case JS_LIST_FORMAT_TYPE : <nl> case JS_LOCALE_TYPE : <nl> case JS_NUMBER_FORMAT_TYPE : <nl> mmm a / src / diagnostics / objects - debug . cc <nl> ppp b / src / diagnostics / objects - debug . cc <nl> <nl> # include " src / objects / js - collection - inl . h " <nl> # ifdef V8_INTL_SUPPORT <nl> # include " src / objects / js - date - time - format - inl . h " <nl> + # include " src / objects / js - display - names - inl . h " <nl> # endif / / V8_INTL_SUPPORT <nl> # include " src / objects / js - generator - inl . h " <nl> # ifdef V8_INTL_SUPPORT <nl> USE_TORQUE_VERIFIER ( JSCollator ) <nl> <nl> USE_TORQUE_VERIFIER ( JSDateTimeFormat ) <nl> <nl> + USE_TORQUE_VERIFIER ( JSDisplayNames ) <nl> + <nl> USE_TORQUE_VERIFIER ( JSListFormat ) <nl> <nl> USE_TORQUE_VERIFIER ( JSLocale ) <nl> mmm a / src / diagnostics / objects - printer . cc <nl> ppp b / src / diagnostics / objects - printer . cc <nl> <nl> # include " src / objects / js - collection - inl . h " <nl> # ifdef V8_INTL_SUPPORT <nl> # include " src / objects / js - date - time - format - inl . h " <nl> + # include " src / objects / js - display - names - inl . h " <nl> # endif / / V8_INTL_SUPPORT <nl> # include " src / objects / js - generator - inl . h " <nl> # ifdef V8_INTL_SUPPORT <nl> void JSDateTimeFormat : : JSDateTimeFormatPrint ( std : : ostream & os ) { / / NOLINT <nl> JSObjectPrintBody ( os , * this ) ; <nl> } <nl> <nl> + void JSDisplayNames : : JSDisplayNamesPrint ( std : : ostream & os ) { / / NOLINT <nl> + JSObjectPrintHeader ( os , * this , " JSDisplayNames " ) ; <nl> + os < < " \ n - internal : " < < Brief ( internal ( ) ) ; <nl> + os < < " \ n - style : " < < StyleAsString ( ) ; <nl> + os < < " \ n - fallback : " < < FallbackAsString ( ) ; <nl> + JSObjectPrintBody ( os , * this ) ; <nl> + } <nl> + <nl> void JSListFormat : : JSListFormatPrint ( std : : ostream & os ) { / / NOLINT <nl> JSObjectPrintHeader ( os , * this , " JSListFormat " ) ; <nl> os < < " \ n - locale : " < < Brief ( locale ( ) ) ; <nl> mmm a / src / flags / flag - definitions . h <nl> ppp b / src / flags / flag - definitions . h <nl> DEFINE_IMPLICATION ( harmony_import_meta , harmony_dynamic_import ) <nl> V ( harmony_top_level_await , " harmony top level await " ) <nl> <nl> # ifdef V8_INTL_SUPPORT <nl> - # define HARMONY_INPROGRESS ( V ) HARMONY_INPROGRESS_BASE ( V ) <nl> + # define HARMONY_INPROGRESS ( V ) \ <nl> + HARMONY_INPROGRESS_BASE ( V ) \ <nl> + V ( harmony_intl_displaynames , " Intl . DisplayNames " ) <nl> # else <nl> # define HARMONY_INPROGRESS ( V ) HARMONY_INPROGRESS_BASE ( V ) <nl> # endif <nl> mmm a / src / init / bootstrapper . cc <nl> ppp b / src / init / bootstrapper . cc <nl> <nl> # include " src / objects / js - break - iterator . h " <nl> # include " src / objects / js - collator . h " <nl> # include " src / objects / js - date - time - format . h " <nl> + # include " src / objects / js - display - names . h " <nl> # include " src / objects / js - list - format . h " <nl> # include " src / objects / js - locale . h " <nl> # include " src / objects / js - number - format . h " <nl> void Genesis : : InitializeGlobal_harmony_intl_segmenter ( ) { <nl> } <nl> } <nl> <nl> + void Genesis : : InitializeGlobal_harmony_intl_displaynames ( ) { <nl> + if ( ! FLAG_harmony_intl_displaynames ) return ; <nl> + Handle < JSObject > intl = Handle < JSObject > : : cast ( <nl> + JSReceiver : : GetProperty ( <nl> + isolate ( ) , <nl> + Handle < JSReceiver > ( native_context ( ) - > global_object ( ) , isolate ( ) ) , <nl> + factory ( ) - > InternalizeUtf8String ( " Intl " ) ) <nl> + . ToHandleChecked ( ) ) ; <nl> + <nl> + Handle < JSFunction > display_names_fun = InstallFunction ( <nl> + isolate ( ) , intl , " DisplayNames " , JS_DISPLAY_NAMES_TYPE , <nl> + JSDisplayNames : : kHeaderSize , 0 , factory ( ) - > the_hole_value ( ) , <nl> + Builtins : : kDisplayNamesConstructor ) ; <nl> + display_names_fun - > shared ( ) . set_length ( 0 ) ; <nl> + display_names_fun - > shared ( ) . DontAdaptArguments ( ) ; <nl> + InstallWithIntrinsicDefaultProto ( isolate_ , display_names_fun , <nl> + Context : : INTL_DISPLAY_NAMES_FUNCTION_INDEX ) ; <nl> + <nl> + SimpleInstallFunction ( isolate ( ) , display_names_fun , " supportedLocalesOf " , <nl> + Builtins : : kDisplayNamesSupportedLocalesOf , 1 , false ) ; <nl> + <nl> + { <nl> + / / Setup % DisplayNamesPrototype % . <nl> + Handle < JSObject > prototype ( <nl> + JSObject : : cast ( display_names_fun - > instance_prototype ( ) ) , isolate ( ) ) ; <nl> + <nl> + InstallToStringTag ( isolate ( ) , prototype , " Intl . DisplayNames " ) ; <nl> + <nl> + SimpleInstallFunction ( isolate ( ) , prototype , " resolvedOptions " , <nl> + Builtins : : kDisplayNamesPrototypeResolvedOptions , 0 , <nl> + false ) ; <nl> + <nl> + SimpleInstallFunction ( isolate ( ) , prototype , " of " , <nl> + Builtins : : kDisplayNamesPrototypeOf , 1 , false ) ; <nl> + } <nl> + } <nl> + <nl> # endif / / V8_INTL_SUPPORT <nl> <nl> Handle < JSFunction > Genesis : : CreateArrayBuffer ( <nl> mmm a / src / init / heap - symbols . h <nl> ppp b / src / init / heap - symbols . h <nl> <nl> V ( _ , currencyDisplay_string , " currencyDisplay " ) \ <nl> V ( _ , currencySign_string , " currencySign " ) \ <nl> V ( _ , dateStyle_string , " dateStyle " ) \ <nl> + V ( _ , dateTimeField_string , " dateTimeField " ) \ <nl> V ( _ , day_string , " day " ) \ <nl> V ( _ , dayPeriod_string , " dayPeriod " ) \ <nl> V ( _ , decimal_string , " decimal " ) \ <nl> <nl> V ( _ , exponentInteger_string , " exponentInteger " ) \ <nl> V ( _ , exponentMinusSign_string , " exponentMinusSign " ) \ <nl> V ( _ , exponentSeparator_string , " exponentSeparator " ) \ <nl> + V ( _ , fallback_string , " fallback " ) \ <nl> V ( _ , first_string , " first " ) \ <nl> V ( _ , format_string , " format " ) \ <nl> V ( _ , fraction_string , " fraction " ) \ <nl> mmm a / src / objects / contexts . h <nl> ppp b / src / objects / contexts . h <nl> enum ContextLookupFlags { <nl> V ( INTL_COLLATOR_FUNCTION_INDEX , JSFunction , intl_collator_function ) \ <nl> V ( INTL_DATE_TIME_FORMAT_FUNCTION_INDEX , JSFunction , \ <nl> intl_date_time_format_function ) \ <nl> + V ( INTL_DISPLAY_NAMES_FUNCTION_INDEX , JSFunction , \ <nl> + intl_display_names_function ) \ <nl> V ( INTL_NUMBER_FORMAT_FUNCTION_INDEX , JSFunction , \ <nl> intl_number_format_function ) \ <nl> V ( INTL_LOCALE_FUNCTION_INDEX , JSFunction , intl_locale_function ) \ <nl> mmm a / src / objects / intl - objects . cc <nl> ppp b / src / objects / intl - objects . cc <nl> bool Intl : : IsWellFormedCalendar ( const std : : string & value ) { <nl> return JSLocale : : Is38AlphaNumList ( value ) ; <nl> } <nl> <nl> + / / ecma402 / # sec - iswellformedcurrencycode <nl> + bool Intl : : IsWellFormedCurrency ( const std : : string & currency ) { <nl> + return JSLocale : : Is3Alpha ( currency ) ; <nl> + } <nl> + <nl> bool Intl : : IsValidCalendar ( const icu : : Locale & locale , <nl> const std : : string & value ) { <nl> return IsValidExtension < icu : : Calendar > ( locale , " calendar " , value ) ; <nl> mmm a / src / objects / intl - objects . h <nl> ppp b / src / objects / intl - objects . h <nl> class Intl { <nl> / / Check the calendar is well formed . <nl> static bool IsWellFormedCalendar ( const std : : string & value ) ; <nl> <nl> + / / Check the currency is well formed . <nl> + static bool IsWellFormedCurrency ( const std : : string & value ) ; <nl> + <nl> struct ResolvedLocale { <nl> std : : string locale ; <nl> icu : : Locale icu_locale ; <nl> mmm a / src / objects / intl - objects . tq <nl> ppp b / src / objects / intl - objects . tq <nl> <nl> <nl> # include ' src / objects / js - break - iterator . h ' <nl> # include ' src / objects / js - collator . h ' <nl> + # include ' src / objects / js - date - time - format . h ' <nl> + # include ' src / objects / js - display - names . h ' <nl> + # include ' src / objects / js - list - format . h ' <nl> + # include ' src / objects / js - locale . h ' <nl> # include ' src / objects / js - number - format . h ' <nl> # include ' src / objects / js - objects . h ' <nl> # include ' src / objects / js - plural - rules . h ' <nl> # include ' src / objects / js - relative - time - format . h ' <nl> - # include ' src / objects / js - date - time - format . h ' <nl> - # include ' src / objects / js - list - format . h ' <nl> - # include ' src / objects / js - locale . h ' <nl> # include ' src / objects / js - segment - iterator . h ' <nl> # include ' src / objects / js - segmenter . h ' <nl> <nl> extern class JSDateTimeFormat extends JSObject { <nl> flags : Smi ; <nl> } <nl> <nl> + extern class JSDisplayNames extends JSObject { <nl> + internal : Foreign ; / / Managed < DisplayNamesInternal > <nl> + flags : Smi ; <nl> + } <nl> + <nl> extern class JSListFormat extends JSObject { <nl> locale : String ; <nl> icu_formatter : Foreign ; / / Managed < icu : : ListFormatter > <nl> new file mode 100644 <nl> index 00000000000 . . 08ad7c0838d <nl> mmm / dev / null <nl> ppp b / src / objects / js - display - names - inl . h <nl> <nl> + / / Copyright 2019 the V8 project authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . <nl> + <nl> + # ifndef V8_INTL_SUPPORT <nl> + # error Internationalization is expected to be enabled . <nl> + # endif / / V8_INTL_SUPPORT <nl> + <nl> + # ifndef V8_OBJECTS_JS_DISPLAY_NAMES_INL_H_ <nl> + # define V8_OBJECTS_JS_DISPLAY_NAMES_INL_H_ <nl> + <nl> + # include " src / objects / js - display - names . h " <nl> + # include " src / objects / objects - inl . h " <nl> + <nl> + / / Has to be the last include ( doesn ' t have include guards ) : <nl> + # include " src / objects / object - macros . h " <nl> + <nl> + namespace v8 { <nl> + namespace internal { <nl> + <nl> + ACCESSORS ( JSDisplayNames , internal , Managed < DisplayNamesInternal > , <nl> + kInternalOffset ) <nl> + OBJECT_CONSTRUCTORS_IMPL ( JSDisplayNames , JSObject ) <nl> + <nl> + / / Base display names accessors . <nl> + SMI_ACCESSORS ( JSDisplayNames , flags , kFlagsOffset ) <nl> + <nl> + CAST_ACCESSOR ( JSDisplayNames ) <nl> + <nl> + inline void JSDisplayNames : : set_style ( Style style ) { <nl> + DCHECK_GE ( StyleBits : : kMax , style ) ; <nl> + set_flags ( StyleBits : : update ( flags ( ) , style ) ) ; <nl> + } <nl> + <nl> + inline JSDisplayNames : : Style JSDisplayNames : : style ( ) const { <nl> + return StyleBits : : decode ( flags ( ) ) ; <nl> + } <nl> + <nl> + inline void JSDisplayNames : : set_fallback ( Fallback fallback ) { <nl> + DCHECK_GE ( FallbackBits : : kMax , fallback ) ; <nl> + int hints = flags ( ) ; <nl> + hints = FallbackBits : : update ( hints , fallback ) ; <nl> + set_flags ( hints ) ; <nl> + } <nl> + <nl> + inline JSDisplayNames : : Fallback JSDisplayNames : : fallback ( ) const { <nl> + return FallbackBits : : decode ( flags ( ) ) ; <nl> + } <nl> + <nl> + } / / namespace internal <nl> + } / / namespace v8 <nl> + <nl> + # include " src / objects / object - macros - undef . h " <nl> + <nl> + # endif / / V8_OBJECTS_JS_DISPLAY_NAMES_INL_H_ <nl> new file mode 100644 <nl> index 00000000000 . . c57bfd59c1c <nl> mmm / dev / null <nl> ppp b / src / objects / js - display - names . cc <nl> <nl> + / / Copyright 2019 the V8 project authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . <nl> + <nl> + # ifndef V8_INTL_SUPPORT <nl> + # error Internationalization is expected to be enabled . <nl> + # endif / / V8_INTL_SUPPORT <nl> + <nl> + # include < memory > <nl> + # include < vector > <nl> + <nl> + # include " src / objects / js - display - names - inl . h " <nl> + # include " src / objects / js - display - names . h " <nl> + <nl> + # include " src / execution / isolate . h " <nl> + # include " src / heap / factory . h " <nl> + # include " src / objects / intl - objects . h " <nl> + # include " src / objects / managed . h " <nl> + # include " src / objects / objects - inl . h " <nl> + <nl> + # include " unicode / dtfmtsym . h " <nl> + # include " unicode / dtptngen . h " <nl> + # include " unicode / localebuilder . h " <nl> + # include " unicode / locdspnm . h " <nl> + # include " unicode / timezone . h " <nl> + # include " unicode / tznames . h " <nl> + # include " unicode / uloc . h " <nl> + # include " unicode / unistr . h " <nl> + # include " unicode / uscript . h " <nl> + <nl> + namespace v8 { <nl> + namespace internal { <nl> + <nl> + / / Type : identifying the types of the display names . <nl> + / / <nl> + / / ecma402 / # sec - properties - of - intl - displaynames - instances <nl> + enum class Type { <nl> + kLanguage , <nl> + kRegion , <nl> + kScript , <nl> + kCurrency , <nl> + kWeekday , <nl> + kMonth , <nl> + kQuarter , <nl> + kDayPeriod , <nl> + kDateTimeField <nl> + } ; <nl> + <nl> + bool IsUnicodeScriptSubtag ( const std : : string & value ) { <nl> + UErrorCode status = U_ZERO_ERROR ; <nl> + icu : : LocaleBuilder builder ; <nl> + builder . setScript ( value ) . build ( status ) ; <nl> + return U_SUCCESS ( status ) ; <nl> + } <nl> + <nl> + bool IsUnicodeRegionSubtag ( const std : : string & value ) { <nl> + UErrorCode status = U_ZERO_ERROR ; <nl> + icu : : LocaleBuilder builder ; <nl> + builder . setRegion ( value ) . build ( status ) ; <nl> + return U_SUCCESS ( status ) ; <nl> + } <nl> + <nl> + UDisplayContext ToUDisplayContext ( JSDisplayNames : : Style style ) { <nl> + switch ( style ) { <nl> + case JSDisplayNames : : Style : : kLong : <nl> + return UDISPCTX_LENGTH_FULL ; <nl> + case JSDisplayNames : : Style : : kShort : <nl> + case JSDisplayNames : : Style : : kNarrow : <nl> + return UDISPCTX_LENGTH_SHORT ; <nl> + } <nl> + } <nl> + <nl> + / / Abstract class for all different types . <nl> + class DisplayNamesInternal { <nl> + public : <nl> + DisplayNamesInternal ( ) { } <nl> + virtual ~ DisplayNamesInternal ( ) { } <nl> + virtual const char * type ( ) const = 0 ; <nl> + virtual icu : : Locale locale ( ) const = 0 ; <nl> + virtual Maybe < icu : : UnicodeString > of ( Isolate * isolate , <nl> + const char * code ) const = 0 ; <nl> + virtual const char * calendar ( ) const { return nullptr ; } <nl> + } ; <nl> + <nl> + class LocaleDisplayNamesCommon : public DisplayNamesInternal { <nl> + public : <nl> + LocaleDisplayNamesCommon ( const icu : : Locale & locale , <nl> + JSDisplayNames : : Style style , bool fallback ) <nl> + : style_ ( style ) { <nl> + UDisplayContext sub = <nl> + fallback ? UDISPCTX_SUBSTITUTE : UDISPCTX_NO_SUBSTITUTE ; <nl> + UDisplayContext display_context [ ] = { ToUDisplayContext ( style_ ) , <nl> + UDISPCTX_DIALECT_NAMES , <nl> + UDISPCTX_CAPITALIZATION_NONE , sub } ; <nl> + ldn_ . reset ( <nl> + icu : : LocaleDisplayNames : : createInstance ( locale , display_context , 4 ) ) ; <nl> + } <nl> + <nl> + virtual ~ LocaleDisplayNamesCommon ( ) { } <nl> + <nl> + icu : : Locale locale ( ) const override { return ldn_ - > getLocale ( ) ; } <nl> + <nl> + protected : <nl> + icu : : LocaleDisplayNames * locale_display_names ( ) const { return ldn_ . get ( ) ; } <nl> + <nl> + private : <nl> + std : : unique_ptr < icu : : LocaleDisplayNames > ldn_ ; <nl> + JSDisplayNames : : Style style_ ; <nl> + } ; <nl> + <nl> + class LanguageNames : public LocaleDisplayNamesCommon { <nl> + public : <nl> + LanguageNames ( const icu : : Locale & locale , JSDisplayNames : : Style style , <nl> + bool fallback ) <nl> + : LocaleDisplayNamesCommon ( locale , style , fallback ) { } <nl> + virtual ~ LanguageNames ( ) { } <nl> + const char * type ( ) const override { return " language " ; } <nl> + Maybe < icu : : UnicodeString > of ( Isolate * isolate , <nl> + const char * code ) const override { <nl> + UErrorCode status = U_ZERO_ERROR ; <nl> + icu : : Locale l = <nl> + icu : : Locale ( icu : : Locale : : forLanguageTag ( code , status ) . getBaseName ( ) ) ; <nl> + std : : string checked = l . toLanguageTag < std : : string > ( status ) ; <nl> + <nl> + if ( U_FAILURE ( status ) ) { <nl> + THROW_NEW_ERROR_RETURN_VALUE ( <nl> + isolate , NewRangeError ( MessageTemplate : : kInvalidArgument ) , <nl> + Nothing < icu : : UnicodeString > ( ) ) ; <nl> + } <nl> + <nl> + icu : : UnicodeString result ; <nl> + locale_display_names ( ) - > localeDisplayName ( checked . c_str ( ) , result ) ; <nl> + <nl> + return Just ( result ) ; <nl> + } <nl> + } ; <nl> + <nl> + class RegionNames : public LocaleDisplayNamesCommon { <nl> + public : <nl> + RegionNames ( const icu : : Locale & locale , JSDisplayNames : : Style style , <nl> + bool fallback ) <nl> + : LocaleDisplayNamesCommon ( locale , style , fallback ) { } <nl> + virtual ~ RegionNames ( ) { } <nl> + const char * type ( ) const override { return " region " ; } <nl> + Maybe < icu : : UnicodeString > of ( Isolate * isolate , <nl> + const char * code ) const override { <nl> + std : : string code_str ( code ) ; <nl> + if ( ! IsUnicodeRegionSubtag ( code_str ) ) { <nl> + THROW_NEW_ERROR_RETURN_VALUE ( <nl> + isolate , NewRangeError ( MessageTemplate : : kInvalidArgument ) , <nl> + Nothing < icu : : UnicodeString > ( ) ) ; <nl> + } <nl> + <nl> + icu : : UnicodeString result ; <nl> + locale_display_names ( ) - > regionDisplayName ( code_str . c_str ( ) , result ) ; <nl> + return Just ( result ) ; <nl> + } <nl> + } ; <nl> + <nl> + class ScriptNames : public LocaleDisplayNamesCommon { <nl> + public : <nl> + ScriptNames ( const icu : : Locale & locale , JSDisplayNames : : Style style , <nl> + bool fallback ) <nl> + : LocaleDisplayNamesCommon ( locale , style , fallback ) { } <nl> + virtual ~ ScriptNames ( ) { } <nl> + const char * type ( ) const override { return " script " ; } <nl> + Maybe < icu : : UnicodeString > of ( Isolate * isolate , <nl> + const char * code ) const override { <nl> + std : : string code_str ( code ) ; <nl> + if ( ! IsUnicodeScriptSubtag ( code_str ) ) { <nl> + THROW_NEW_ERROR_RETURN_VALUE ( <nl> + isolate , NewRangeError ( MessageTemplate : : kInvalidArgument ) , <nl> + Nothing < icu : : UnicodeString > ( ) ) ; <nl> + } <nl> + <nl> + icu : : UnicodeString result ; <nl> + locale_display_names ( ) - > scriptDisplayName ( code_str . c_str ( ) , result ) ; <nl> + return Just ( result ) ; <nl> + } <nl> + } ; <nl> + <nl> + class CurrencyNames : public LocaleDisplayNamesCommon { <nl> + public : <nl> + CurrencyNames ( const icu : : Locale & locale , JSDisplayNames : : Style style , <nl> + bool fallback ) <nl> + : LocaleDisplayNamesCommon ( locale , style , fallback ) { } <nl> + virtual ~ CurrencyNames ( ) { } <nl> + const char * type ( ) const override { return " currency " ; } <nl> + Maybe < icu : : UnicodeString > of ( Isolate * isolate , <nl> + const char * code ) const override { <nl> + std : : string code_str ( code ) ; <nl> + if ( ! Intl : : IsWellFormedCurrency ( code_str ) ) { <nl> + THROW_NEW_ERROR_RETURN_VALUE ( <nl> + isolate , NewRangeError ( MessageTemplate : : kInvalidArgument ) , <nl> + Nothing < icu : : UnicodeString > ( ) ) ; <nl> + } <nl> + <nl> + icu : : UnicodeString result ; <nl> + locale_display_names ( ) - > keyValueDisplayName ( " currency " , code_str . c_str ( ) , <nl> + result ) ; <nl> + <nl> + return Just ( result ) ; <nl> + } <nl> + } ; <nl> + <nl> + UDateTimePGDisplayWidth StyleToUDateTimePGDisplayWidth ( <nl> + JSDisplayNames : : Style style ) { <nl> + switch ( style ) { <nl> + case JSDisplayNames : : Style : : kLong : <nl> + return UDATPG_WIDE ; <nl> + case JSDisplayNames : : Style : : kShort : <nl> + return UDATPG_ABBREVIATED ; <nl> + case JSDisplayNames : : Style : : kNarrow : <nl> + return UDATPG_NARROW ; <nl> + } <nl> + } <nl> + <nl> + UDateTimePatternField StringToUDateTimePatternField ( const char * code ) { <nl> + switch ( code [ 0 ] ) { <nl> + case ' d ' : <nl> + if ( strcmp ( code , " day " ) = = 0 ) return UDATPG_DAY_FIELD ; <nl> + if ( strcmp ( code , " dayPeriod " ) = = 0 ) return UDATPG_DAYPERIOD_FIELD ; <nl> + break ; <nl> + case ' e ' : <nl> + if ( strcmp ( code , " era " ) = = 0 ) return UDATPG_ERA_FIELD ; <nl> + break ; <nl> + case ' h ' : <nl> + if ( strcmp ( code , " hour " ) = = 0 ) return UDATPG_HOUR_FIELD ; <nl> + break ; <nl> + case ' m ' : <nl> + if ( strcmp ( code , " minute " ) = = 0 ) return UDATPG_MINUTE_FIELD ; <nl> + if ( strcmp ( code , " month " ) = = 0 ) return UDATPG_MONTH_FIELD ; <nl> + break ; <nl> + case ' q ' : <nl> + if ( strcmp ( code , " quarter " ) = = 0 ) return UDATPG_QUARTER_FIELD ; <nl> + break ; <nl> + case ' s ' : <nl> + if ( strcmp ( code , " second " ) = = 0 ) return UDATPG_SECOND_FIELD ; <nl> + break ; <nl> + case ' t ' : <nl> + if ( strcmp ( code , " timeZoneName " ) = = 0 ) return UDATPG_ZONE_FIELD ; <nl> + break ; <nl> + case ' w ' : <nl> + if ( strcmp ( code , " weekOfYear " ) = = 0 ) return UDATPG_WEEK_OF_YEAR_FIELD ; <nl> + if ( strcmp ( code , " weekday " ) = = 0 ) return UDATPG_WEEKDAY_FIELD ; <nl> + break ; <nl> + case ' y ' : <nl> + if ( strcmp ( code , " year " ) = = 0 ) return UDATPG_YEAR_FIELD ; <nl> + break ; <nl> + default : <nl> + break ; <nl> + } <nl> + UNREACHABLE ( ) ; <nl> + } <nl> + <nl> + class DateTimeFieldNames : public DisplayNamesInternal { <nl> + public : <nl> + DateTimeFieldNames ( const icu : : Locale & locale , JSDisplayNames : : Style style ) <nl> + : locale_ ( locale ) , width_ ( StyleToUDateTimePGDisplayWidth ( style ) ) { <nl> + UErrorCode status = U_ZERO_ERROR ; <nl> + generator_ . reset ( <nl> + icu : : DateTimePatternGenerator : : createInstance ( locale_ , status ) ) ; <nl> + CHECK ( U_SUCCESS ( status ) ) ; <nl> + } <nl> + virtual ~ DateTimeFieldNames ( ) { } <nl> + const char * type ( ) const override { return " dateTimeField " ; } <nl> + icu : : Locale locale ( ) const override { return locale_ ; } <nl> + Maybe < icu : : UnicodeString > of ( Isolate * isolate , <nl> + const char * code ) const override { <nl> + UDateTimePatternField field = StringToUDateTimePatternField ( code ) ; <nl> + if ( field = = UDATPG_FIELD_COUNT ) { <nl> + THROW_NEW_ERROR_RETURN_VALUE ( <nl> + isolate , NewRangeError ( MessageTemplate : : kInvalidArgument ) , <nl> + Nothing < icu : : UnicodeString > ( ) ) ; <nl> + } <nl> + return Just ( generator_ - > getFieldDisplayName ( field , width_ ) ) ; <nl> + } <nl> + <nl> + private : <nl> + icu : : Locale locale_ ; <nl> + UDateTimePGDisplayWidth width_ ; <nl> + std : : unique_ptr < icu : : DateTimePatternGenerator > generator_ ; <nl> + } ; <nl> + <nl> + icu : : DateFormatSymbols : : DtWidthType StyleToDtWidthType ( <nl> + JSDisplayNames : : Style style , Type type ) { <nl> + switch ( style ) { <nl> + case JSDisplayNames : : Style : : kLong : <nl> + return icu : : DateFormatSymbols : : WIDE ; <nl> + case JSDisplayNames : : Style : : kShort : <nl> + return icu : : DateFormatSymbols : : SHORT ; <nl> + case JSDisplayNames : : Style : : kNarrow : <nl> + if ( type = = Type : : kQuarter ) { <nl> + return icu : : DateFormatSymbols : : ABBREVIATED ; <nl> + } else { <nl> + return icu : : DateFormatSymbols : : NARROW ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + class DateFormatSymbolsNames : public DisplayNamesInternal { <nl> + public : <nl> + DateFormatSymbolsNames ( const char * type , const icu : : Locale & locale , <nl> + const icu : : UnicodeString * array , int32_t length , <nl> + const char * calendar ) <nl> + : type_ ( type ) , <nl> + locale_ ( locale ) , <nl> + array_ ( array ) , <nl> + length_ ( length ) , <nl> + calendar_ ( calendar ) { } <nl> + <nl> + virtual ~ DateFormatSymbolsNames ( ) { } <nl> + <nl> + const char * type ( ) const override { return type_ ; } <nl> + <nl> + icu : : Locale locale ( ) const override { return locale_ ; } <nl> + <nl> + const char * calendar ( ) const override { <nl> + if ( calendar_ . empty ( ) ) { <nl> + return nullptr ; <nl> + } <nl> + return calendar_ . c_str ( ) ; <nl> + } <nl> + <nl> + virtual int32_t ComputeIndex ( const char * code ) const = 0 ; <nl> + <nl> + Maybe < icu : : UnicodeString > of ( Isolate * isolate , <nl> + const char * code ) const override { <nl> + int32_t index = ComputeIndex ( code ) ; <nl> + if ( index < 0 | | index > = length_ ) { <nl> + THROW_NEW_ERROR_RETURN_VALUE ( <nl> + isolate , NewRangeError ( MessageTemplate : : kInvalidArgument ) , <nl> + Nothing < icu : : UnicodeString > ( ) ) ; <nl> + } <nl> + return Just ( array_ [ index ] ) ; <nl> + } <nl> + <nl> + private : <nl> + const char * type_ ; <nl> + icu : : Locale locale_ ; <nl> + const icu : : UnicodeString * array_ ; <nl> + int32_t length_ ; <nl> + std : : string calendar_ ; <nl> + } ; <nl> + <nl> + class WeekdayNames : public DateFormatSymbolsNames { <nl> + public : <nl> + WeekdayNames ( const char * type , const icu : : Locale & locale , <nl> + const icu : : UnicodeString * array , int32_t length , <nl> + const char * calendar ) <nl> + : DateFormatSymbolsNames ( type , locale , array , length , calendar ) { } <nl> + virtual ~ WeekdayNames ( ) { } <nl> + <nl> + int32_t ComputeIndex ( const char * code ) const override { <nl> + int32_t i = atoi ( code ) ; <nl> + if ( i = = 7 ) return 1 ; <nl> + if ( i > 0 & & i < 7 ) return i + 1 ; <nl> + return - 1 ; <nl> + } <nl> + } ; <nl> + <nl> + class MonthNames : public DateFormatSymbolsNames { <nl> + public : <nl> + MonthNames ( const char * type , const icu : : Locale & locale , <nl> + const icu : : UnicodeString * array , int32_t length , <nl> + const char * calendar ) <nl> + : DateFormatSymbolsNames ( type , locale , array , length , calendar ) { } <nl> + virtual ~ MonthNames ( ) { } <nl> + <nl> + int32_t ComputeIndex ( const char * code ) const override { <nl> + return atoi ( code ) - 1 ; <nl> + } <nl> + } ; <nl> + <nl> + class QuarterNames : public DateFormatSymbolsNames { <nl> + public : <nl> + QuarterNames ( const char * type , const icu : : Locale & locale , <nl> + const icu : : UnicodeString * array , int32_t length , <nl> + const char * calendar ) <nl> + : DateFormatSymbolsNames ( type , locale , array , length , calendar ) { } <nl> + virtual ~ QuarterNames ( ) { } <nl> + <nl> + int32_t ComputeIndex ( const char * code ) const override { <nl> + return atoi ( code ) - 1 ; <nl> + } <nl> + } ; <nl> + <nl> + class DayPeriodNames : public DateFormatSymbolsNames { <nl> + public : <nl> + DayPeriodNames ( const char * type , const icu : : Locale & locale , <nl> + const icu : : UnicodeString * array , int32_t length , <nl> + const char * calendar ) <nl> + : DateFormatSymbolsNames ( type , locale , array , length , calendar ) { } <nl> + virtual ~ DayPeriodNames ( ) { } <nl> + <nl> + int32_t ComputeIndex ( const char * code ) const override { <nl> + if ( strcmp ( " am " , code ) = = 0 ) { <nl> + return 0 ; <nl> + } else if ( strcmp ( " pm " , code ) = = 0 ) { <nl> + return 1 ; <nl> + } else { <nl> + return - 1 ; <nl> + } <nl> + } <nl> + } ; <nl> + <nl> + const char * gWeekday = " weekday " ; <nl> + const char * gMonth = " month " ; <nl> + const char * gQuarter = " quarter " ; <nl> + const char * gDayPeriod = " dayPeriod " ; <nl> + <nl> + DateFormatSymbolsNames * CreateDateFormatSymbolsNames ( <nl> + const icu : : Locale & locale , JSDisplayNames : : Style style , Type type ) { <nl> + UErrorCode status = U_ZERO_ERROR ; <nl> + std : : unique_ptr < icu : : DateFormatSymbols > symbols ( <nl> + icu : : DateFormatSymbols : : createForLocale ( locale , status ) ) ; <nl> + if ( U_FAILURE ( status ) ) { <nl> + return nullptr ; <nl> + } <nl> + icu : : DateFormatSymbols : : DtWidthType width_type = <nl> + StyleToDtWidthType ( style , type ) ; <nl> + int32_t count = 0 ; <nl> + std : : string calendar = <nl> + locale . getUnicodeKeywordValue < std : : string > ( " ca " , status ) ; <nl> + <nl> + switch ( type ) { <nl> + case Type : : kMonth : <nl> + return new MonthNames ( <nl> + gMonth , locale , <nl> + symbols - > getMonths ( count , icu : : DateFormatSymbols : : STANDALONE , <nl> + width_type ) , <nl> + count , calendar . c_str ( ) ) ; <nl> + case Type : : kWeekday : <nl> + return new WeekdayNames ( <nl> + gWeekday , locale , <nl> + symbols - > getWeekdays ( count , icu : : DateFormatSymbols : : STANDALONE , <nl> + width_type ) , <nl> + count , calendar . c_str ( ) ) ; <nl> + case Type : : kQuarter : <nl> + return new QuarterNames ( <nl> + gQuarter , locale , <nl> + symbols - > getQuarters ( count , icu : : DateFormatSymbols : : STANDALONE , <nl> + width_type ) , <nl> + count , calendar . c_str ( ) ) ; <nl> + case Type : : kDayPeriod : <nl> + return new DayPeriodNames ( gDayPeriod , locale , <nl> + symbols - > getAmPmStrings ( count ) , count , <nl> + calendar . c_str ( ) ) ; <nl> + default : <nl> + UNREACHABLE ( ) ; <nl> + } <nl> + } <nl> + <nl> + DisplayNamesInternal * CreateInternal ( const icu : : Locale & locale , <nl> + JSDisplayNames : : Style style , Type type , <nl> + bool fallback ) { <nl> + switch ( type ) { <nl> + case Type : : kLanguage : <nl> + return new LanguageNames ( locale , style , fallback ) ; <nl> + case Type : : kRegion : <nl> + return new RegionNames ( locale , style , fallback ) ; <nl> + case Type : : kScript : <nl> + return new ScriptNames ( locale , style , fallback ) ; <nl> + case Type : : kCurrency : <nl> + return new CurrencyNames ( locale , style , fallback ) ; <nl> + case Type : : kDateTimeField : <nl> + return new DateTimeFieldNames ( locale , style ) ; <nl> + case Type : : kMonth : <nl> + case Type : : kWeekday : <nl> + case Type : : kQuarter : <nl> + case Type : : kDayPeriod : <nl> + return CreateDateFormatSymbolsNames ( locale , style , type ) ; <nl> + default : <nl> + UNREACHABLE ( ) ; <nl> + } <nl> + } <nl> + / / ecma402 # sec - Intl . DisplayNames <nl> + MaybeHandle < JSDisplayNames > JSDisplayNames : : New ( Isolate * isolate , <nl> + Handle < Map > map , <nl> + Handle < Object > locales , <nl> + Handle < Object > input_options ) { <nl> + const char * service = " Intl . DisplayNames " ; <nl> + Factory * factory = isolate - > factory ( ) ; <nl> + <nl> + Handle < JSReceiver > options ; <nl> + / / 3 . Let requestedLocales be ? CanonicalizeLocaleList ( locales ) . <nl> + Maybe < std : : vector < std : : string > > maybe_requested_locales = <nl> + Intl : : CanonicalizeLocaleList ( isolate , locales ) ; <nl> + MAYBE_RETURN ( maybe_requested_locales , Handle < JSDisplayNames > ( ) ) ; <nl> + std : : vector < std : : string > requested_locales = <nl> + maybe_requested_locales . FromJust ( ) ; <nl> + <nl> + / / 4 . If options is undefined , then <nl> + if ( input_options - > IsUndefined ( isolate ) ) { <nl> + / / 4 . a . Let options be ObjectCreate ( null ) . <nl> + options = factory - > NewJSObjectWithNullProto ( ) ; <nl> + / / 5 . Else <nl> + } else { <nl> + / / 5 . a . Let options be ? ToObject ( options ) . <nl> + ASSIGN_RETURN_ON_EXCEPTION ( isolate , options , <nl> + Object : : ToObject ( isolate , input_options ) , <nl> + JSDisplayNames ) ; <nl> + } <nl> + <nl> + / / Note : No need to create a record . It ' s not observable . <nl> + / / 6 . Let opt be a new Record . <nl> + <nl> + / / 7 . Let localeData be % DisplayNames % . [ [ LocaleData ] ] . <nl> + <nl> + / / 8 . Let matcher be ? GetOption ( options , " localeMatcher " , " string " , « <nl> + / / " lookup " , " best fit " » , " best fit " ) . <nl> + Maybe < Intl : : MatcherOption > maybe_locale_matcher = <nl> + Intl : : GetLocaleMatcher ( isolate , options , " Intl . DisplayNames " ) ; <nl> + MAYBE_RETURN ( maybe_locale_matcher , MaybeHandle < JSDisplayNames > ( ) ) ; <nl> + <nl> + / / 9 . Set opt . [ [ localeMatcher ] ] to matcher . <nl> + Intl : : MatcherOption matcher = maybe_locale_matcher . FromJust ( ) ; <nl> + <nl> + std : : unique_ptr < char [ ] > calendar_str = nullptr ; <nl> + const std : : vector < const char * > empty_values = { } ; <nl> + / / 10 . Let calendar be ? GetOption ( options , " calendar " , <nl> + / / " string " , undefined , undefined ) . <nl> + Maybe < bool > maybe_calendar = Intl : : GetStringOption ( <nl> + isolate , options , " calendar " , empty_values , service , & calendar_str ) ; <nl> + MAYBE_RETURN ( maybe_calendar , MaybeHandle < JSDisplayNames > ( ) ) ; <nl> + / / 11 . If calendar is not undefined , then <nl> + if ( maybe_calendar . FromJust ( ) & & calendar_str ! = nullptr ) { <nl> + / / a . If calendar does not match the ( 3 * 8alphanum ) * ( " - " ( 3 * 8alphanum ) ) <nl> + / / sequence , throw a RangeError exception . <nl> + if ( ! Intl : : IsWellFormedCalendar ( calendar_str . get ( ) ) ) { <nl> + THROW_NEW_ERROR ( <nl> + isolate , <nl> + NewRangeError ( MessageTemplate : : kInvalid , factory - > calendar_string ( ) , <nl> + factory - > NewStringFromAsciiChecked ( calendar_str . get ( ) ) ) , <nl> + JSDisplayNames ) ; <nl> + } <nl> + } <nl> + <nl> + / / 12 . Set opt . [ [ ca ] ] to calendar . <nl> + <nl> + / / ecma402 / # sec - Intl . DisplayNames - internal - slots <nl> + / / The value of the [ [ RelevantExtensionKeys ] ] internal slot is <nl> + / / « " ca " » . <nl> + std : : set < std : : string > relevant_extension_keys = { " ca " } ; <nl> + / / 13 . Let r be ResolveLocale ( % DisplayNames % . [ [ AvailableLocales ] ] , <nl> + / / requestedLocales , opt , % DisplayNames % . [ [ RelevantExtensionKeys ] ] ) . <nl> + Intl : : ResolvedLocale r = <nl> + Intl : : ResolveLocale ( isolate , JSDisplayNames : : GetAvailableLocales ( ) , <nl> + requested_locales , matcher , relevant_extension_keys ) ; <nl> + <nl> + icu : : Locale icu_locale = r . icu_locale ; <nl> + UErrorCode status = U_ZERO_ERROR ; <nl> + if ( calendar_str ! = nullptr & & <nl> + Intl : : IsValidCalendar ( icu_locale , calendar_str . get ( ) ) ) { <nl> + icu_locale . setUnicodeKeywordValue ( " ca " , calendar_str . get ( ) , status ) ; <nl> + CHECK ( U_SUCCESS ( status ) ) ; <nl> + } <nl> + <nl> + / / 14 . Let s be ? GetOption ( options , " style " , " string " , <nl> + / / « " long " , " short " , " narrow " » , " long " ) . <nl> + Maybe < Style > maybe_style = Intl : : GetStringOption < Style > ( <nl> + isolate , options , " style " , " Intl . DisplayNames " , <nl> + { " long " , " short " , " narrow " } , <nl> + { Style : : kLong , Style : : kShort , Style : : kNarrow } , Style : : kLong ) ; <nl> + MAYBE_RETURN ( maybe_style , MaybeHandle < JSDisplayNames > ( ) ) ; <nl> + Style style_enum = maybe_style . FromJust ( ) ; <nl> + <nl> + / / 15 . Set displayNames . [ [ Style ] ] to style . <nl> + <nl> + / / 16 . Let type be ? GetOption ( options , " type " , " string " , « " language " , <nl> + / / " region " , " script " , " currency " , " weekday " , " month " , " quarter " , <nl> + / / " dayPeriod " , " dateTimeField " » , " language " ) . <nl> + Maybe < Type > maybe_type = Intl : : GetStringOption < Type > ( <nl> + isolate , options , " type " , " Intl . DisplayNames " , <nl> + { " language " , " region " , " script " , " currency " , " weekday " , " month " , <nl> + " quarter " , " dayPeriod " , " dateTimeField " } , <nl> + { <nl> + Type : : kLanguage , <nl> + Type : : kRegion , <nl> + Type : : kScript , <nl> + Type : : kCurrency , <nl> + Type : : kWeekday , <nl> + Type : : kMonth , <nl> + Type : : kQuarter , <nl> + Type : : kDayPeriod , <nl> + Type : : kDateTimeField , <nl> + } , <nl> + Type : : kLanguage ) ; <nl> + MAYBE_RETURN ( maybe_type , MaybeHandle < JSDisplayNames > ( ) ) ; <nl> + Type type_enum = maybe_type . FromJust ( ) ; <nl> + <nl> + / / 17 . Set displayNames . [ [ Type ] ] to type . <nl> + <nl> + / / 18 . Let fallback be ? GetOption ( options , " fallback " , " string " , <nl> + / / « " code " , " none " » , " code " ) . <nl> + Maybe < Fallback > maybe_fallback = Intl : : GetStringOption < Fallback > ( <nl> + isolate , options , " fallback " , " Intl . DisplayNames " , { " code " , " none " } , <nl> + { Fallback : : kCode , Fallback : : kNone } , Fallback : : kCode ) ; <nl> + MAYBE_RETURN ( maybe_fallback , MaybeHandle < JSDisplayNames > ( ) ) ; <nl> + Fallback fallback_enum = maybe_fallback . FromJust ( ) ; <nl> + <nl> + / / 19 . Set displayNames . [ [ Fallback ] ] to fallback . <nl> + <nl> + / / 20 . Set displayNames . [ [ Locale ] ] to the value of r . [ [ Locale ] ] . <nl> + <nl> + / / Let calendar be r . [ [ ca ] ] . <nl> + <nl> + / / Set displayNames . [ [ Calendar ] ] to calendar . <nl> + <nl> + / / Let dataLocale be r . [ [ dataLocale ] ] . <nl> + <nl> + / / Let dataLocaleData be localeData . [ [ < dataLocale > ] ] . <nl> + <nl> + / / Let types be dataLocaleData . [ [ types ] ] . <nl> + <nl> + / / Assert : types is a Record ( see 1 . 3 . 3 ) . <nl> + <nl> + / / Let typeFields be types . [ [ < type > ] ] . <nl> + <nl> + / / Assert : typeFields is a Record ( see 1 . 3 . 3 ) . <nl> + <nl> + / / Let styleFields be typeFields . [ [ < style > ] ] . <nl> + <nl> + / / Assert : styleFields is a Record ( see 1 . 3 . 3 ) . <nl> + <nl> + / / Set displayNames . [ [ Fields ] ] to styleFields . <nl> + <nl> + DisplayNamesInternal * internal = CreateInternal ( <nl> + icu_locale , style_enum , type_enum , fallback_enum = = Fallback : : kCode ) ; <nl> + if ( internal = = nullptr ) { <nl> + THROW_NEW_ERROR ( isolate , NewTypeError ( MessageTemplate : : kIcuError ) , <nl> + JSDisplayNames ) ; <nl> + } <nl> + <nl> + Handle < Managed < DisplayNamesInternal > > managed_internal = <nl> + Managed < DisplayNamesInternal > : : FromRawPtr ( isolate , 0 , internal ) ; <nl> + <nl> + Handle < JSDisplayNames > display_names = <nl> + Handle < JSDisplayNames > : : cast ( factory - > NewFastOrSlowJSObjectFromMap ( map ) ) ; <nl> + display_names - > set_flags ( 0 ) ; <nl> + display_names - > set_style ( style_enum ) ; <nl> + display_names - > set_fallback ( fallback_enum ) ; <nl> + <nl> + DisallowHeapAllocation no_gc ; <nl> + display_names - > set_internal ( * managed_internal ) ; <nl> + <nl> + / / Return displayNames . <nl> + return display_names ; <nl> + } <nl> + <nl> + / / ecma402 # sec - Intl . DisplayNames . prototype . resolvedOptions <nl> + Handle < JSObject > JSDisplayNames : : ResolvedOptions ( <nl> + Isolate * isolate , Handle < JSDisplayNames > display_names ) { <nl> + Factory * factory = isolate - > factory ( ) ; <nl> + / / 4 . Let options be ! ObjectCreate ( % ObjectPrototype % ) . <nl> + Handle < JSObject > options = factory - > NewJSObject ( isolate - > object_function ( ) ) ; <nl> + <nl> + DisplayNamesInternal * internal = display_names - > internal ( ) . raw ( ) ; <nl> + <nl> + Maybe < std : : string > maybe_locale = Intl : : ToLanguageTag ( internal - > locale ( ) ) ; <nl> + CHECK ( maybe_locale . IsJust ( ) ) ; <nl> + Handle < String > locale = isolate - > factory ( ) - > NewStringFromAsciiChecked ( <nl> + maybe_locale . FromJust ( ) . c_str ( ) ) ; <nl> + Handle < String > style = display_names - > StyleAsString ( ) ; <nl> + Handle < String > type = factory - > NewStringFromAsciiChecked ( internal - > type ( ) ) ; <nl> + Handle < String > fallback = display_names - > FallbackAsString ( ) ; <nl> + <nl> + CHECK ( JSReceiver : : CreateDataProperty ( isolate , options , <nl> + factory - > locale_string ( ) , locale , <nl> + Just ( kDontThrow ) ) <nl> + . FromJust ( ) ) ; <nl> + if ( internal - > calendar ( ) ! = nullptr ) { <nl> + CHECK ( JSReceiver : : CreateDataProperty ( <nl> + isolate , options , factory - > calendar_string ( ) , <nl> + factory - > NewStringFromAsciiChecked ( internal - > calendar ( ) ) , <nl> + Just ( kDontThrow ) ) <nl> + . FromJust ( ) ) ; <nl> + } <nl> + CHECK ( JSReceiver : : CreateDataProperty ( <nl> + isolate , options , factory - > style_string ( ) , style , Just ( kDontThrow ) ) <nl> + . FromJust ( ) ) ; <nl> + <nl> + CHECK ( JSReceiver : : CreateDataProperty ( isolate , options , factory - > type_string ( ) , <nl> + type , Just ( kDontThrow ) ) <nl> + . FromJust ( ) ) ; <nl> + CHECK ( JSReceiver : : CreateDataProperty ( isolate , options , <nl> + factory - > fallback_string ( ) , fallback , <nl> + Just ( kDontThrow ) ) <nl> + . FromJust ( ) ) ; <nl> + <nl> + return options ; <nl> + } <nl> + <nl> + / / ecma402 # sec - Intl . DisplayNames . prototype . of <nl> + MaybeHandle < Object > JSDisplayNames : : Of ( Isolate * isolate , <nl> + Handle < JSDisplayNames > display_names , <nl> + Handle < Object > code_obj ) { <nl> + Handle < String > code ; <nl> + ASSIGN_RETURN_ON_EXCEPTION ( isolate , code , Object : : ToString ( isolate , code_obj ) , <nl> + Object ) ; <nl> + DisplayNamesInternal * internal = display_names - > internal ( ) . raw ( ) ; <nl> + Maybe < icu : : UnicodeString > maybe_result = <nl> + internal - > of ( isolate , code - > ToCString ( ) . get ( ) ) ; <nl> + MAYBE_RETURN ( maybe_result , Handle < Object > ( ) ) ; <nl> + icu : : UnicodeString result = maybe_result . FromJust ( ) ; <nl> + if ( result . isBogus ( ) ) { <nl> + return isolate - > factory ( ) - > undefined_value ( ) ; <nl> + } <nl> + return Intl : : ToString ( isolate , result ) . ToHandleChecked ( ) ; <nl> + } <nl> + <nl> + namespace { <nl> + <nl> + struct CheckCalendar { <nl> + static const char * key ( ) { return " calendar " ; } <nl> + static const char * path ( ) { return nullptr ; } <nl> + } ; <nl> + <nl> + } / / namespace <nl> + <nl> + const std : : set < std : : string > & JSDisplayNames : : GetAvailableLocales ( ) { <nl> + static base : : LazyInstance < <nl> + Intl : : AvailableLocales < icu : : Locale , CheckCalendar > > : : type <nl> + available_locales = LAZY_INSTANCE_INITIALIZER ; <nl> + return available_locales . Pointer ( ) - > Get ( ) ; <nl> + } <nl> + <nl> + Handle < String > JSDisplayNames : : StyleAsString ( ) const { <nl> + switch ( style ( ) ) { <nl> + case Style : : kLong : <nl> + return GetReadOnlyRoots ( ) . long_string_handle ( ) ; <nl> + case Style : : kShort : <nl> + return GetReadOnlyRoots ( ) . short_string_handle ( ) ; <nl> + case Style : : kNarrow : <nl> + return GetReadOnlyRoots ( ) . narrow_string_handle ( ) ; <nl> + } <nl> + UNREACHABLE ( ) ; <nl> + } <nl> + <nl> + Handle < String > JSDisplayNames : : FallbackAsString ( ) const { <nl> + switch ( fallback ( ) ) { <nl> + case Fallback : : kCode : <nl> + return GetReadOnlyRoots ( ) . code_string_handle ( ) ; <nl> + case Fallback : : kNone : <nl> + return GetReadOnlyRoots ( ) . none_string_handle ( ) ; <nl> + } <nl> + UNREACHABLE ( ) ; <nl> + } <nl> + <nl> + } / / namespace internal <nl> + } / / namespace v8 <nl> new file mode 100644 <nl> index 00000000000 . . f3fc9c9282e <nl> mmm / dev / null <nl> ppp b / src / objects / js - display - names . h <nl> <nl> + / / Copyright 2019 the V8 project authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . <nl> + <nl> + # ifndef V8_INTL_SUPPORT <nl> + # error Internationalization is expected to be enabled . <nl> + # endif / / V8_INTL_SUPPORT <nl> + <nl> + # ifndef V8_OBJECTS_JS_DISPLAY_NAMES_H_ <nl> + # define V8_OBJECTS_JS_DISPLAY_NAMES_H_ <nl> + <nl> + # include < set > <nl> + # include < string > <nl> + <nl> + # include " src / execution / isolate . h " <nl> + # include " src / heap / factory . h " <nl> + # include " src / objects / managed . h " <nl> + # include " src / objects / objects . h " <nl> + <nl> + / / Has to be the last include ( doesn ' t have include guards ) : <nl> + # include " src / objects / object - macros . h " <nl> + <nl> + namespace v8 { <nl> + namespace internal { <nl> + <nl> + class DisplayNamesInternal ; <nl> + <nl> + class JSDisplayNames : public JSObject { <nl> + public : <nl> + / / Creates display names object with properties derived from input <nl> + / / locales and options . <nl> + static MaybeHandle < JSDisplayNames > New ( Isolate * isolate , Handle < Map > map , <nl> + Handle < Object > locales , <nl> + Handle < Object > options ) ; <nl> + <nl> + static Handle < JSObject > ResolvedOptions ( Isolate * isolate , <nl> + Handle < JSDisplayNames > format_holder ) ; <nl> + <nl> + static MaybeHandle < Object > Of ( Isolate * isolate , Handle < JSDisplayNames > holder , <nl> + Handle < Object > code_obj ) ; <nl> + <nl> + V8_EXPORT_PRIVATE static const std : : set < std : : string > & GetAvailableLocales ( ) ; <nl> + <nl> + Handle < String > StyleAsString ( ) const ; <nl> + Handle < String > FallbackAsString ( ) const ; <nl> + <nl> + / / Style : identifying the display names style used . <nl> + / / <nl> + / / ecma402 / # sec - properties - of - intl - displaynames - instances <nl> + enum class Style { <nl> + kLong , / / Everything spelled out . <nl> + kShort , / / Abbreviations used when possible . <nl> + kNarrow / / Use the shortest possible form . <nl> + } ; <nl> + inline void set_style ( Style style ) ; <nl> + inline Style style ( ) const ; <nl> + <nl> + / / Type : identifying the fallback of the display names . <nl> + / / <nl> + / / ecma402 / # sec - properties - of - intl - displaynames - instances <nl> + enum class Fallback { <nl> + kCode , <nl> + kNone , <nl> + } ; <nl> + inline void set_fallback ( Fallback fallback ) ; <nl> + inline Fallback fallback ( ) const ; <nl> + <nl> + DECL_CAST ( JSDisplayNames ) <nl> + <nl> + / / Bit positions in | flags | . <nl> + # define FLAGS_BIT_FIELDS ( V , _ ) \ <nl> + V ( StyleBits , Style , 2 , _ ) \ <nl> + V ( FallbackBits , Fallback , 1 , _ ) <nl> + DEFINE_BIT_FIELDS ( FLAGS_BIT_FIELDS ) <nl> + # undef FLAGS_BIT_FIELDS <nl> + <nl> + STATIC_ASSERT ( Style : : kLong < = StyleBits : : kMax ) ; <nl> + STATIC_ASSERT ( Style : : kShort < = StyleBits : : kMax ) ; <nl> + STATIC_ASSERT ( Style : : kNarrow < = StyleBits : : kMax ) ; <nl> + STATIC_ASSERT ( Fallback : : kCode < = FallbackBits : : kMax ) ; <nl> + STATIC_ASSERT ( Fallback : : kNone < = FallbackBits : : kMax ) ; <nl> + <nl> + / / [ flags ] Bit field containing various flags about the function . <nl> + DECL_INT_ACCESSORS ( flags ) <nl> + <nl> + DECL_ACCESSORS ( internal , Managed < DisplayNamesInternal > ) <nl> + <nl> + DECL_PRINTER ( JSDisplayNames ) <nl> + DECL_VERIFIER ( JSDisplayNames ) <nl> + <nl> + / / Layout description . <nl> + DEFINE_FIELD_OFFSET_CONSTANTS ( JSObject : : kHeaderSize , <nl> + TORQUE_GENERATED_JS_DISPLAY_NAMES_FIELDS ) <nl> + <nl> + OBJECT_CONSTRUCTORS ( JSDisplayNames , JSObject ) ; <nl> + } ; <nl> + <nl> + } / / namespace internal <nl> + } / / namespace v8 <nl> + <nl> + # include " src / objects / object - macros - undef . h " <nl> + <nl> + # endif / / V8_OBJECTS_JS_DISPLAY_NAMES_H_ <nl> mmm a / src / objects / js - locale . cc <nl> ppp b / src / objects / js - locale . cc <nl> bool JSLocale : : Is38AlphaNumList ( const std : : string & value ) { <nl> JSLocale : : Is38AlphaNumList ( value . substr ( found + 1 ) ) ; <nl> } <nl> <nl> + bool JSLocale : : Is3Alpha ( const std : : string & value ) { <nl> + return IsAlpha ( value , 3 , 3 ) ; <nl> + } <nl> + <nl> / / TODO ( ftang ) Replace the following check w / icu : : LocaleBuilder <nl> / / once ICU64 land in March 2019 . <nl> bool JSLocale : : StartsWithUnicodeLanguageId ( const std : : string & value ) { <nl> mmm a / src / objects / js - locale . h <nl> ppp b / src / objects / js - locale . h <nl> class JSLocale : public JSObject { <nl> / / " ( 3 * 8alphanum ) * ( " - " ( 3 * 8alphanum ) ) sequence " sequence <nl> static bool Is38AlphaNumList ( const std : : string & value ) ; <nl> <nl> + / / Help function to check well - formed " 3alpha " <nl> + static bool Is3Alpha ( const std : : string & value ) ; <nl> + <nl> DECL_CAST ( JSLocale ) <nl> <nl> DECL_ACCESSORS ( icu_locale , Managed < icu : : Locale > ) <nl> mmm a / src / objects / js - objects . cc <nl> ppp b / src / objects / js - objects . cc <nl> <nl> # include " src / objects / js - collection . h " <nl> # ifdef V8_INTL_SUPPORT <nl> # include " src / objects / js - date - time - format . h " <nl> + # include " src / objects / js - display - names . h " <nl> # endif / / V8_INTL_SUPPORT <nl> # include " src / objects / js - generator - inl . h " <nl> # ifdef V8_INTL_SUPPORT <nl> int JSObject : : GetHeaderSize ( InstanceType type , <nl> return JSCollator : : kHeaderSize ; <nl> case JS_DATE_TIME_FORMAT_TYPE : <nl> return JSDateTimeFormat : : kHeaderSize ; <nl> + case JS_DISPLAY_NAMES_TYPE : <nl> + return JSDisplayNames : : kHeaderSize ; <nl> case JS_LIST_FORMAT_TYPE : <nl> return JSListFormat : : kHeaderSize ; <nl> case JS_LOCALE_TYPE : <nl> bool CanSubclassHaveInobjectProperties ( InstanceType instance_type ) { <nl> # ifdef V8_INTL_SUPPORT <nl> case JS_COLLATOR_TYPE : <nl> case JS_DATE_TIME_FORMAT_TYPE : <nl> + case JS_DISPLAY_NAMES_TYPE : <nl> case JS_LIST_FORMAT_TYPE : <nl> case JS_LOCALE_TYPE : <nl> case JS_NUMBER_FORMAT_TYPE : <nl> mmm a / src / objects / map . cc <nl> ppp b / src / objects / map . cc <nl> VisitorId Map : : GetVisitorId ( Map map ) { <nl> case JS_V8_BREAK_ITERATOR_TYPE : <nl> case JS_COLLATOR_TYPE : <nl> case JS_DATE_TIME_FORMAT_TYPE : <nl> + case JS_DISPLAY_NAMES_TYPE : <nl> case JS_LIST_FORMAT_TYPE : <nl> case JS_LOCALE_TYPE : <nl> case JS_NUMBER_FORMAT_TYPE : <nl> mmm a / src / objects / object - list - macros . h <nl> ppp b / src / objects / object - list - macros . h <nl> class ZoneForwardList ; <nl> V ( JSV8BreakIterator ) \ <nl> V ( JSCollator ) \ <nl> V ( JSDateTimeFormat ) \ <nl> + V ( JSDisplayNames ) \ <nl> V ( JSListFormat ) \ <nl> V ( JSLocale ) \ <nl> V ( JSNumberFormat ) \ <nl> mmm a / src / objects / objects - body - descriptors - inl . h <nl> ppp b / src / objects / objects - body - descriptors - inl . h <nl> ReturnType BodyDescriptorApply ( InstanceType type , T1 p1 , T2 p2 , T3 p3 , T4 p4 ) { <nl> case JS_V8_BREAK_ITERATOR_TYPE : <nl> case JS_COLLATOR_TYPE : <nl> case JS_DATE_TIME_FORMAT_TYPE : <nl> + case JS_DISPLAY_NAMES_TYPE : <nl> case JS_LIST_FORMAT_TYPE : <nl> case JS_LOCALE_TYPE : <nl> case JS_NUMBER_FORMAT_TYPE : <nl> mmm a / src / objects / objects . h <nl> ppp b / src / objects / objects . h <nl> <nl> / / - JSWeakSet <nl> / / - JSCollator / / If V8_INTL_SUPPORT enabled . <nl> / / - JSDateTimeFormat / / If V8_INTL_SUPPORT enabled . <nl> + / / - JSDisplayNames / / If V8_INTL_SUPPORT enabled . <nl> / / - JSListFormat / / If V8_INTL_SUPPORT enabled . <nl> / / - JSLocale / / If V8_INTL_SUPPORT enabled . <nl> / / - JSNumberFormat / / If V8_INTL_SUPPORT enabled . <nl> new file mode 100644 <nl> index 00000000000 . . 6951b5fddb9 <nl> mmm / dev / null <nl> ppp b / test / intl / displaynames / constructor - order . js <nl> <nl> + / / Copyright 2019 the V8 project authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . <nl> + <nl> + / / Flags : - - harmony - intl - displaynames <nl> + <nl> + / / Throws only once during construction . <nl> + / / Check for all getters to prevent regression . <nl> + / / Preserve the order of getter initialization . <nl> + let getCount = 0 ; <nl> + <nl> + new Intl . DisplayNames ( [ ' en - US ' ] , { <nl> + get localeMatcher ( ) { <nl> + assertEquals ( 0 , getCount + + ) ; <nl> + } , <nl> + get style ( ) { <nl> + assertEquals ( 1 , getCount + + ) ; <nl> + } , <nl> + get type ( ) { <nl> + assertEquals ( 2 , getCount + + ) ; <nl> + } , <nl> + get fallback ( ) { <nl> + assertEquals ( 3 , getCount + + ) ; <nl> + } , <nl> + } ) ; <nl> + assertEquals ( 4 , getCount ) ; <nl> new file mode 100644 <nl> index 00000000000 . . 49acb1f2e2b <nl> mmm / dev / null <nl> ppp b / test / intl / displaynames / constructor . js <nl> <nl> + / / Copyright 2019 the V8 project authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . <nl> + <nl> + / / Flags : - - harmony - intl - displaynames <nl> + / / DisplayNames constructor can ' t be called as function . <nl> + assertThrows ( ( ) = > Intl . DisplayNames ( ' sr ' ) , TypeError ) ; <nl> + <nl> + assertDoesNotThrow ( ( ) = > new Intl . DisplayNames ( ' sr ' , { } ) ) ; <nl> + <nl> + assertDoesNotThrow ( ( ) = > new Intl . DisplayNames ( [ ] , { } ) ) ; <nl> + <nl> + assertDoesNotThrow ( ( ) = > new Intl . DisplayNames ( [ ' fr ' , ' ar ' ] , { } ) ) ; <nl> + <nl> + assertDoesNotThrow ( ( ) = > new Intl . DisplayNames ( { 0 : ' ja ' , 1 : ' fr ' } , { } ) ) ; <nl> + <nl> + assertDoesNotThrow ( ( ) = > new Intl . DisplayNames ( { 1 : ' ja ' , 2 : ' fr ' } , { } ) ) ; <nl> + <nl> + assertDoesNotThrow ( ( ) = > new Intl . DisplayNames ( ' sr ' ) ) ; <nl> + <nl> + assertDoesNotThrow ( ( ) = > new Intl . DisplayNames ( ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( <nl> + ' sr ' , { <nl> + localeMatcher : ' lookup ' , <nl> + style : ' short ' , <nl> + type : ' language ' , <nl> + fallback : ' code ' , <nl> + } ) ) ; <nl> + <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { localeMatcher : ' lookup ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { localeMatcher : ' best fit ' } ) ) ; <nl> + <nl> + assertThrows ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { localeMatcher : ' hello ' } ) , <nl> + RangeError ) ; <nl> + <nl> + assertThrows ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { localeMatcher : ' look up ' } ) , <nl> + RangeError ) ; <nl> + <nl> + assertThrows ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { localeMatcher : ' bestfit ' } ) , <nl> + RangeError ) ; <nl> + <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { style : ' long ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { style : ' short ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { style : ' narrow ' } ) ) ; <nl> + <nl> + assertThrows ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { style : ' giant ' } ) , <nl> + RangeError ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { fallback : ' code ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { fallback : ' none ' } ) ) ; <nl> + <nl> + assertThrows ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { fallback : ' never ' } ) , <nl> + RangeError ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { type : ' language ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { type : ' region ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { type : ' script ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { type : ' currency ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { type : ' month ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { type : ' weekday ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { type : ' quarter ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { type : ' dayPeriod ' } ) ) ; <nl> + <nl> + assertDoesNotThrow ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { type : ' dateTimeField ' } ) ) ; <nl> + <nl> + assertThrows ( <nl> + ( ) = > new Intl . DisplayNames ( ' sr ' , { type : ' ' } ) , <nl> + RangeError ) ; <nl> new file mode 100644 <nl> index 00000000000 . . df619c00307 <nl> mmm / dev / null <nl> ppp b / test / intl / displaynames / resolved - options . js <nl> <nl> + / / Copyright 2019 the V8 project authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . <nl> + <nl> + / / Flags : - - harmony - intl - displaynames <nl> + <nl> + let displayNames = new Intl . DisplayNames ( ) ; <nl> + / / The default style is ' long ' <nl> + assertEquals ( ' long ' , displayNames . resolvedOptions ( ) . style ) ; <nl> + <nl> + / / The default type is ' language ' <nl> + assertEquals ( ' language ' , displayNames . resolvedOptions ( ) . type ) ; <nl> + <nl> + / / The default fallback is ' code ' <nl> + assertEquals ( ' code ' , displayNames . resolvedOptions ( ) . fallback ) ; <nl> + <nl> + const styles = [ " long " , " short " , " narrow " ] ; <nl> + const types = [ " language " , " region " , " script " , " currency " , " weekday " , " month " , <nl> + " quarter " , " dayPeriod " , " dateTimeField " ] ; <nl> + const fallbacks = [ " code " , " none " ] ; <nl> + <nl> + styles . forEach ( function ( style ) { <nl> + assertEquals ( style , <nl> + ( new Intl . DisplayNames ( [ ' sr ' ] , { style } ) ) . resolvedOptions ( ) . style ) ; <nl> + assertEquals ( types [ 0 ] , <nl> + ( new Intl . DisplayNames ( [ ' sr ' ] , { style } ) ) . resolvedOptions ( ) . type ) ; <nl> + assertEquals ( fallbacks [ 0 ] , <nl> + ( new Intl . DisplayNames ( [ ' sr ' ] , { style } ) ) . resolvedOptions ( ) . fallback ) ; <nl> + types . forEach ( function ( type ) { <nl> + assertEquals ( style , <nl> + ( new Intl . DisplayNames ( [ ' sr ' ] , { style , type } ) ) . resolvedOptions ( ) . style ) ; <nl> + assertEquals ( type , <nl> + ( new Intl . DisplayNames ( [ ' sr ' ] , { style , type } ) ) . resolvedOptions ( ) . type ) ; <nl> + assertEquals ( fallbacks [ 0 ] , <nl> + ( new Intl . DisplayNames ( <nl> + [ ' sr ' ] , { style , type } ) ) . resolvedOptions ( ) . fallback ) ; <nl> + fallbacks . forEach ( function ( fallback ) { <nl> + assertEquals ( style , <nl> + ( new Intl . DisplayNames ( <nl> + [ ' sr ' ] , { style , type , fallback } ) ) . resolvedOptions ( ) . style ) ; <nl> + assertEquals ( type , <nl> + ( new Intl . DisplayNames ( <nl> + [ ' sr ' ] , { style , type , fallback } ) ) . resolvedOptions ( ) . type ) ; <nl> + assertEquals ( fallback , <nl> + ( new Intl . DisplayNames ( <nl> + [ ' sr ' ] , { style , type , fallback } ) ) . resolvedOptions ( ) . fallback ) ; <nl> + } ) ; <nl> + } ) ; <nl> + } ) ; <nl> new file mode 100644 <nl> index 00000000000 . . d6c65be233e <nl> mmm / dev / null <nl> ppp b / test / intl / displaynames / supported - locale . js <nl> <nl> + / / Copyright 2019 the V8 project authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . <nl> + <nl> + / / Flags : - - harmony - intl - displaynames <nl> + <nl> + assertEquals ( typeof Intl . DisplayNames . supportedLocalesOf , " function " , <nl> + " Intl . DisplayNames . supportedLocalesOf should be a function " ) ; <nl> + <nl> + var undef = Intl . DisplayNames . supportedLocalesOf ( ) ; <nl> + assertEquals ( [ ] , undef ) ; <nl> + <nl> + var empty = Intl . DisplayNames . supportedLocalesOf ( [ ] ) ; <nl> + assertEquals ( [ ] , empty ) ; <nl> + <nl> + var strLocale = Intl . DisplayNames . supportedLocalesOf ( ' sr ' ) ; <nl> + assertEquals ( ' sr ' , strLocale [ 0 ] ) ; <nl> + <nl> + var multiLocale = [ ' sr - Thai - RS ' , ' de ' , ' zh - CN ' ] ; <nl> + assertEquals ( multiLocale , Intl . DisplayNames . supportedLocalesOf ( multiLocale ) ) ; <nl> mmm a / test / test262 / test262 . status <nl> ppp b / test / test262 / test262 . status <nl> <nl> # https : / / bugs . chromium . org / p / v8 / issues / detail ? id = 7472 <nl> ' intl402 / NumberFormat / currency - digits ' : [ FAIL ] , <nl> <nl> - # https : / / bugs . chromium . org / p / v8 / issues / detail ? id = 8703 <nl> - ' intl402 / DisplayNames / ctor - custom - get - prototype - poison - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / ctor - custom - prototype ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / ctor - default - prototype ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / instance - extensible ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / length ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / locales - length - poison - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / locales - length - tolength - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / locales - symbol - length ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / name ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - fallback - abrupt - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - fallback - invalid - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - fallback - toString - abrupt - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - fallback - valid ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - localeMatcher - abrupt - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - localeMatcher - invalid - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - localeMatcher - toString - abrupt - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - localeMatcher - valid ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - random - properties - unchecked ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - style - abrupt - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - style - invalid - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - style - toString - abrupt - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - style - valid ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - type - abrupt - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - type - invalid - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - type - toString - abrupt - throws ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / options - type - valid ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / prop - desc ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / proto ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / proto - from - ctor - realm ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / prototype / prop - desc ' : [ FAIL ] , <nl> - ' intl402 / DisplayNames / prototype / Symbol . toStringTag ' : [ FAIL ] , <nl> - <nl> # https : / / bugs . chromium . org / p / v8 / issues / detail ? id = 7831 <nl> ' language / statements / generators / generator - created - after - decl - inst ' : [ FAIL ] , <nl> ' language / expressions / generators / generator - created - after - decl - inst ' : [ FAIL ] , <nl> mmm a / test / test262 / testcfg . py <nl> ppp b / test / test262 / testcfg . py <nl> <nl> ' Intl . DateTimeFormat - dayPeriod ' : ' - - harmony - intl - dateformat - day - period ' , <nl> ' Intl . DateTimeFormat - quarter ' : ' - - harmony - intl - dateformat - quarter ' , <nl> ' Intl . DateTimeFormat - fractionalSecondDigits ' : ' - - harmony - intl - dateformat - fractional - second - digits ' , <nl> + ' Intl . DisplayNames ' : ' - - harmony - intl - displaynames ' , <nl> ' Symbol . prototype . description ' : ' - - harmony - symbol - description ' , <nl> ' export - star - as - namespace - from - module ' : ' - - harmony - namespace - exports ' , <nl> ' Promise . allSettled ' : ' - - harmony - promise - all - settled ' , <nl> mmm a / tools / heap - stats / categories . js <nl> ppp b / tools / heap - stats / categories . js <nl> const CATEGORIES = new Map ( [ <nl> ' JS_GLOBAL_PROXY_TYPE ' , <nl> ' JS_COLLATOR_TYPE ' , <nl> ' JS_DATE_TIME_FORMAT_TYPE ' , <nl> + ' JS_DISPLAY_NAMES_TYPE ' , <nl> ' JS_LIST_FORMAT_TYPE ' , <nl> ' JS_LOCALE_TYPE ' , <nl> ' JS_NUMBER_FORMAT_TYPE ' , <nl> mmm a / tools / v8heapconst . py <nl> ppp b / tools / v8heapconst . py <nl> <nl> 1064 : " JS_CONTEXT_EXTENSION_OBJECT_TYPE " , <nl> 1065 : " JS_DATE_TYPE " , <nl> 1066 : " JS_DATE_TIME_FORMAT_TYPE " , <nl> - 1067 : " JS_ERROR_TYPE " , <nl> - 1068 : " JS_FINALIZATION_GROUP_TYPE " , <nl> - 1069 : " JS_FINALIZATION_GROUP_CLEANUP_ITERATOR_TYPE " , <nl> - 1070 : " JS_LIST_FORMAT_TYPE " , <nl> - 1071 : " JS_LOCALE_TYPE " , <nl> - 1072 : " JS_MESSAGE_OBJECT_TYPE " , <nl> - 1073 : " JS_NUMBER_FORMAT_TYPE " , <nl> - 1074 : " JS_PLURAL_RULES_TYPE " , <nl> - 1075 : " JS_PROMISE_TYPE " , <nl> - 1076 : " JS_REG_EXP_TYPE " , <nl> - 1077 : " JS_REG_EXP_STRING_ITERATOR_TYPE " , <nl> - 1078 : " JS_RELATIVE_TIME_FORMAT_TYPE " , <nl> - 1079 : " JS_SEGMENT_ITERATOR_TYPE " , <nl> - 1080 : " JS_SEGMENTER_TYPE " , <nl> - 1081 : " JS_STRING_ITERATOR_TYPE " , <nl> - 1082 : " JS_V8_BREAK_ITERATOR_TYPE " , <nl> - 1083 : " JS_WEAK_REF_TYPE " , <nl> - 1084 : " WASM_EXCEPTION_OBJECT_TYPE " , <nl> - 1085 : " WASM_GLOBAL_OBJECT_TYPE " , <nl> - 1086 : " WASM_INSTANCE_OBJECT_TYPE " , <nl> - 1087 : " WASM_MEMORY_OBJECT_TYPE " , <nl> - 1088 : " WASM_MODULE_OBJECT_TYPE " , <nl> - 1089 : " WASM_TABLE_OBJECT_TYPE " , <nl> - 1090 : " JS_BOUND_FUNCTION_TYPE " , <nl> - 1091 : " JS_FUNCTION_TYPE " , <nl> + 1067 : " JS_DISPLAY_NAMES_TYPE " , <nl> + 1068 : " JS_ERROR_TYPE " , <nl> + 1069 : " JS_FINALIZATION_GROUP_TYPE " , <nl> + 1070 : " JS_FINALIZATION_GROUP_CLEANUP_ITERATOR_TYPE " , <nl> + 1071 : " JS_LIST_FORMAT_TYPE " , <nl> + 1072 : " JS_LOCALE_TYPE " , <nl> + 1073 : " JS_MESSAGE_OBJECT_TYPE " , <nl> + 1074 : " JS_NUMBER_FORMAT_TYPE " , <nl> + 1075 : " JS_PLURAL_RULES_TYPE " , <nl> + 1076 : " JS_PROMISE_TYPE " , <nl> + 1077 : " JS_REG_EXP_TYPE " , <nl> + 1078 : " JS_REG_EXP_STRING_ITERATOR_TYPE " , <nl> + 1079 : " JS_RELATIVE_TIME_FORMAT_TYPE " , <nl> + 1080 : " JS_SEGMENT_ITERATOR_TYPE " , <nl> + 1081 : " JS_SEGMENTER_TYPE " , <nl> + 1082 : " JS_STRING_ITERATOR_TYPE " , <nl> + 1083 : " JS_V8_BREAK_ITERATOR_TYPE " , <nl> + 1084 : " JS_WEAK_REF_TYPE " , <nl> + 1085 : " WASM_EXCEPTION_OBJECT_TYPE " , <nl> + 1086 : " WASM_GLOBAL_OBJECT_TYPE " , <nl> + 1087 : " WASM_INSTANCE_OBJECT_TYPE " , <nl> + 1088 : " WASM_MEMORY_OBJECT_TYPE " , <nl> + 1089 : " WASM_MODULE_OBJECT_TYPE " , <nl> + 1090 : " WASM_TABLE_OBJECT_TYPE " , <nl> + 1091 : " JS_BOUND_FUNCTION_TYPE " , <nl> + 1092 : " JS_FUNCTION_TYPE " , <nl> } <nl> <nl> # List of known V8 maps . <nl> <nl> ( " read_only_space " , 0x01d79 ) : ( 92 , " EnumCacheMap " ) , <nl> ( " read_only_space " , 0x01e11 ) : ( 86 , " ArrayBoilerplateDescriptionMap " ) , <nl> ( " read_only_space " , 0x01ff9 ) : ( 95 , " InterceptorInfoMap " ) , <nl> - ( " read_only_space " , 0x04969 ) : ( 71 , " PromiseFulfillReactionJobTaskMap " ) , <nl> - ( " read_only_space " , 0x049b1 ) : ( 72 , " PromiseRejectReactionJobTaskMap " ) , <nl> - ( " read_only_space " , 0x049f9 ) : ( 73 , " CallableTaskMap " ) , <nl> - ( " read_only_space " , 0x04a41 ) : ( 74 , " CallbackTaskMap " ) , <nl> - ( " read_only_space " , 0x04a89 ) : ( 75 , " PromiseResolveThenableJobTaskMap " ) , <nl> - ( " read_only_space " , 0x04ad1 ) : ( 78 , " FunctionTemplateInfoMap " ) , <nl> - ( " read_only_space " , 0x04b19 ) : ( 79 , " ObjectTemplateInfoMap " ) , <nl> - ( " read_only_space " , 0x04b61 ) : ( 80 , " AccessCheckInfoMap " ) , <nl> - ( " read_only_space " , 0x04ba9 ) : ( 81 , " AccessorInfoMap " ) , <nl> - ( " read_only_space " , 0x04bf1 ) : ( 82 , " AccessorPairMap " ) , <nl> - ( " read_only_space " , 0x04c39 ) : ( 83 , " AliasedArgumentsEntryMap " ) , <nl> - ( " read_only_space " , 0x04c81 ) : ( 84 , " AllocationMementoMap " ) , <nl> - ( " read_only_space " , 0x04cc9 ) : ( 87 , " AsmWasmDataMap " ) , <nl> - ( " read_only_space " , 0x04d11 ) : ( 88 , " AsyncGeneratorRequestMap " ) , <nl> - ( " read_only_space " , 0x04d59 ) : ( 90 , " ClassPositionsMap " ) , <nl> - ( " read_only_space " , 0x04da1 ) : ( 91 , " DebugInfoMap " ) , <nl> - ( " read_only_space " , 0x04de9 ) : ( 94 , " FunctionTemplateRareDataMap " ) , <nl> - ( " read_only_space " , 0x04e31 ) : ( 97 , " InterpreterDataMap " ) , <nl> - ( " read_only_space " , 0x04e79 ) : ( 98 , " PromiseCapabilityMap " ) , <nl> - ( " read_only_space " , 0x04ec1 ) : ( 99 , " PromiseReactionMap " ) , <nl> - ( " read_only_space " , 0x04f09 ) : ( 100 , " PrototypeInfoMap " ) , <nl> - ( " read_only_space " , 0x04f51 ) : ( 101 , " ScriptMap " ) , <nl> - ( " read_only_space " , 0x04f99 ) : ( 105 , " SourcePositionTableWithFrameCacheMap " ) , <nl> - ( " read_only_space " , 0x04fe1 ) : ( 106 , " SourceTextModuleInfoEntryMap " ) , <nl> - ( " read_only_space " , 0x05029 ) : ( 107 , " StackFrameInfoMap " ) , <nl> - ( " read_only_space " , 0x05071 ) : ( 108 , " StackTraceFrameMap " ) , <nl> - ( " read_only_space " , 0x050b9 ) : ( 109 , " TemplateObjectDescriptionMap " ) , <nl> - ( " read_only_space " , 0x05101 ) : ( 110 , " Tuple2Map " ) , <nl> - ( " read_only_space " , 0x05149 ) : ( 111 , " Tuple3Map " ) , <nl> - ( " read_only_space " , 0x05191 ) : ( 112 , " WasmCapiFunctionDataMap " ) , <nl> - ( " read_only_space " , 0x051d9 ) : ( 113 , " WasmDebugInfoMap " ) , <nl> - ( " read_only_space " , 0x05221 ) : ( 114 , " WasmExceptionTagMap " ) , <nl> - ( " read_only_space " , 0x05269 ) : ( 115 , " WasmExportedFunctionDataMap " ) , <nl> - ( " read_only_space " , 0x052b1 ) : ( 116 , " WasmIndirectFunctionTableMap " ) , <nl> - ( " read_only_space " , 0x052f9 ) : ( 117 , " WasmJSFunctionDataMap " ) , <nl> - ( " read_only_space " , 0x05341 ) : ( 96 , " InternalClassMap " ) , <nl> - ( " read_only_space " , 0x05389 ) : ( 103 , " SmiPairMap " ) , <nl> - ( " read_only_space " , 0x053d1 ) : ( 102 , " SmiBoxMap " ) , <nl> - ( " read_only_space " , 0x05419 ) : ( 104 , " SortStateMap " ) , <nl> - ( " read_only_space " , 0x05461 ) : ( 85 , " AllocationSiteWithWeakNextMap " ) , <nl> - ( " read_only_space " , 0x054a9 ) : ( 85 , " AllocationSiteWithoutWeakNextMap " ) , <nl> - ( " read_only_space " , 0x054f1 ) : ( 76 , " LoadHandler1Map " ) , <nl> - ( " read_only_space " , 0x05539 ) : ( 76 , " LoadHandler2Map " ) , <nl> - ( " read_only_space " , 0x05581 ) : ( 76 , " LoadHandler3Map " ) , <nl> - ( " read_only_space " , 0x055c9 ) : ( 77 , " StoreHandler0Map " ) , <nl> - ( " read_only_space " , 0x05611 ) : ( 77 , " StoreHandler1Map " ) , <nl> - ( " read_only_space " , 0x05659 ) : ( 77 , " StoreHandler2Map " ) , <nl> - ( " read_only_space " , 0x056a1 ) : ( 77 , " StoreHandler3Map " ) , <nl> + ( " read_only_space " , 0x049a1 ) : ( 71 , " PromiseFulfillReactionJobTaskMap " ) , <nl> + ( " read_only_space " , 0x049e9 ) : ( 72 , " PromiseRejectReactionJobTaskMap " ) , <nl> + ( " read_only_space " , 0x04a31 ) : ( 73 , " CallableTaskMap " ) , <nl> + ( " read_only_space " , 0x04a79 ) : ( 74 , " CallbackTaskMap " ) , <nl> + ( " read_only_space " , 0x04ac1 ) : ( 75 , " PromiseResolveThenableJobTaskMap " ) , <nl> + ( " read_only_space " , 0x04b09 ) : ( 78 , " FunctionTemplateInfoMap " ) , <nl> + ( " read_only_space " , 0x04b51 ) : ( 79 , " ObjectTemplateInfoMap " ) , <nl> + ( " read_only_space " , 0x04b99 ) : ( 80 , " AccessCheckInfoMap " ) , <nl> + ( " read_only_space " , 0x04be1 ) : ( 81 , " AccessorInfoMap " ) , <nl> + ( " read_only_space " , 0x04c29 ) : ( 82 , " AccessorPairMap " ) , <nl> + ( " read_only_space " , 0x04c71 ) : ( 83 , " AliasedArgumentsEntryMap " ) , <nl> + ( " read_only_space " , 0x04cb9 ) : ( 84 , " AllocationMementoMap " ) , <nl> + ( " read_only_space " , 0x04d01 ) : ( 87 , " AsmWasmDataMap " ) , <nl> + ( " read_only_space " , 0x04d49 ) : ( 88 , " AsyncGeneratorRequestMap " ) , <nl> + ( " read_only_space " , 0x04d91 ) : ( 90 , " ClassPositionsMap " ) , <nl> + ( " read_only_space " , 0x04dd9 ) : ( 91 , " DebugInfoMap " ) , <nl> + ( " read_only_space " , 0x04e21 ) : ( 94 , " FunctionTemplateRareDataMap " ) , <nl> + ( " read_only_space " , 0x04e69 ) : ( 97 , " InterpreterDataMap " ) , <nl> + ( " read_only_space " , 0x04eb1 ) : ( 98 , " PromiseCapabilityMap " ) , <nl> + ( " read_only_space " , 0x04ef9 ) : ( 99 , " PromiseReactionMap " ) , <nl> + ( " read_only_space " , 0x04f41 ) : ( 100 , " PrototypeInfoMap " ) , <nl> + ( " read_only_space " , 0x04f89 ) : ( 101 , " ScriptMap " ) , <nl> + ( " read_only_space " , 0x04fd1 ) : ( 105 , " SourcePositionTableWithFrameCacheMap " ) , <nl> + ( " read_only_space " , 0x05019 ) : ( 106 , " SourceTextModuleInfoEntryMap " ) , <nl> + ( " read_only_space " , 0x05061 ) : ( 107 , " StackFrameInfoMap " ) , <nl> + ( " read_only_space " , 0x050a9 ) : ( 108 , " StackTraceFrameMap " ) , <nl> + ( " read_only_space " , 0x050f1 ) : ( 109 , " TemplateObjectDescriptionMap " ) , <nl> + ( " read_only_space " , 0x05139 ) : ( 110 , " Tuple2Map " ) , <nl> + ( " read_only_space " , 0x05181 ) : ( 111 , " Tuple3Map " ) , <nl> + ( " read_only_space " , 0x051c9 ) : ( 112 , " WasmCapiFunctionDataMap " ) , <nl> + ( " read_only_space " , 0x05211 ) : ( 113 , " WasmDebugInfoMap " ) , <nl> + ( " read_only_space " , 0x05259 ) : ( 114 , " WasmExceptionTagMap " ) , <nl> + ( " read_only_space " , 0x052a1 ) : ( 115 , " WasmExportedFunctionDataMap " ) , <nl> + ( " read_only_space " , 0x052e9 ) : ( 116 , " WasmIndirectFunctionTableMap " ) , <nl> + ( " read_only_space " , 0x05331 ) : ( 117 , " WasmJSFunctionDataMap " ) , <nl> + ( " read_only_space " , 0x05379 ) : ( 96 , " InternalClassMap " ) , <nl> + ( " read_only_space " , 0x053c1 ) : ( 103 , " SmiPairMap " ) , <nl> + ( " read_only_space " , 0x05409 ) : ( 102 , " SmiBoxMap " ) , <nl> + ( " read_only_space " , 0x05451 ) : ( 104 , " SortStateMap " ) , <nl> + ( " read_only_space " , 0x05499 ) : ( 85 , " AllocationSiteWithWeakNextMap " ) , <nl> + ( " read_only_space " , 0x054e1 ) : ( 85 , " AllocationSiteWithoutWeakNextMap " ) , <nl> + ( " read_only_space " , 0x05529 ) : ( 76 , " LoadHandler1Map " ) , <nl> + ( " read_only_space " , 0x05571 ) : ( 76 , " LoadHandler2Map " ) , <nl> + ( " read_only_space " , 0x055b9 ) : ( 76 , " LoadHandler3Map " ) , <nl> + ( " read_only_space " , 0x05601 ) : ( 77 , " StoreHandler0Map " ) , <nl> + ( " read_only_space " , 0x05649 ) : ( 77 , " StoreHandler1Map " ) , <nl> + ( " read_only_space " , 0x05691 ) : ( 77 , " StoreHandler2Map " ) , <nl> + ( " read_only_space " , 0x056d9 ) : ( 77 , " StoreHandler3Map " ) , <nl> ( " map_space " , 0x00119 ) : ( 1057 , " ExternalMap " ) , <nl> - ( " map_space " , 0x00161 ) : ( 1072 , " JSMessageObjectMap " ) , <nl> + ( " map_space " , 0x00161 ) : ( 1073 , " JSMessageObjectMap " ) , <nl> } <nl> <nl> # List of known V8 objects . <nl>
[ Intl ] Prototype Intl . DisplayNames
v8/v8
162c5b0ff973c7af1123338e78beb62d9f747dd8
2019-11-18T21:48:22Z
mmm a / tests / cpp - tests / Classes / Texture2dTest / Texture2dTest . cpp <nl> ppp b / tests / cpp - tests / Classes / Texture2dTest / Texture2dTest . cpp <nl> void TextureAsync : : onEnter ( ) <nl> <nl> TextureAsync : : ~ TextureAsync ( ) <nl> { <nl> - Director : : getInstance ( ) - > getTextureCache ( ) - > unbindAllImageAsync ( ) ; <nl> - Director : : getInstance ( ) - > getTextureCache ( ) - > removeAllTextures ( ) ; <nl> + auto textureCache = Director : : getInstance ( ) - > getTextureCache ( ) ; <nl> + textureCache - > unbindAllImageAsync ( ) ; <nl> + textureCache - > removeAllTextures ( ) ; <nl> } <nl> <nl> void TextureAsync : : loadImages ( float dt ) <nl> { <nl> + auto textureCache = Director : : getInstance ( ) - > getTextureCache ( ) ; <nl> for ( int i = 0 ; i < 8 ; i + + ) { <nl> for ( int j = 0 ; j < 8 ; j + + ) { <nl> char szSpriteName [ 100 ] = { 0 } ; <nl> sprintf ( szSpriteName , " Images / sprites_test / sprite - % d - % d . png " , i , j ) ; <nl> - Director : : getInstance ( ) - > getTextureCache ( ) - > addImageAsync ( szSpriteName , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> + textureCache - > addImageAsync ( szSpriteName , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> } <nl> } <nl> <nl> - Director : : getInstance ( ) - > getTextureCache ( ) - > addImageAsync ( " Images / background1 . jpg " , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> - Director : : getInstance ( ) - > getTextureCache ( ) - > addImageAsync ( " Images / background2 . jpg " , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> - Director : : getInstance ( ) - > getTextureCache ( ) - > addImageAsync ( " Images / background . png " , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> - Director : : getInstance ( ) - > getTextureCache ( ) - > addImageAsync ( " Images / atlastest . png " , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> - Director : : getInstance ( ) - > getTextureCache ( ) - > addImageAsync ( " Images / grossini_dance_atlas . png " , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> + textureCache - > addImageAsync ( " Images / background1 . jpg " , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> + textureCache - > addImageAsync ( " Images / background2 . jpg " , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> + textureCache - > addImageAsync ( " Images / background . png " , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> + textureCache - > addImageAsync ( " Images / atlastest . png " , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> + textureCache - > addImageAsync ( " Images / grossini_dance_atlas . png " , CC_CALLBACK_1 ( TextureAsync : : imageLoaded , this ) ) ; <nl> } <nl> <nl> <nl>
Merge pull request from ricardoquesada / async_fixes_test
cocos2d/cocos2d-x
f8b9e9e44515edab143e0f694e83c9c0ff509402
2014-11-25T18:44:27Z
mmm a / . azure - pipelines / linux . yml <nl> ppp b / . azure - pipelines / linux . yml <nl> <nl> - resources : <nl> - containers : <nl> - - container : envoy - build <nl> - image : envoyproxy / envoy - build : 8246167b9d238797cbc6c03dccc9e3921c37617d <nl> - <nl> jobs : <nl> - - job : EnvoyFullTest <nl> + - job : bazel <nl> + strategy : <nl> + matrix : <nl> + release : <nl> + CI_TARGET : ' bazel . release ' <nl> + dependsOn : [ ] # this removes the implicit dependency on previous stage and causes this to run in parallel . <nl> timeoutInMinutes : 360 <nl> pool : <nl> vmImage : ' Ubuntu 16 . 04 ' <nl> - container : envoy - build <nl> steps : <nl> - bash : | <nl> echo " disk space at beginning of build : " <nl> df - h <nl> + displayName : " Check disk space at beginning " <nl> + <nl> + - bash : | <nl> + sudo mkdir - p / etc / docker <nl> + echo ' { <nl> + " ipv6 " : true , <nl> + " fixed - cidr - v6 " : " 2001 : db8 : 1 : : / 64 " <nl> + } ' | sudo tee / etc / docker / daemon . json <nl> + sudo service docker restart <nl> + displayName : " Enable IPv6 " <nl> <nl> - - script : ci / do_ci . sh bazel . release <nl> + - script : ci / run_envoy_docker . sh ' ci / do_ci . sh $ ( CI_TARGET ) ' <nl> + workingDirectory : $ ( Build . SourcesDirectory ) <nl> env : <nl> - ENVOY_SRCDIR : $ ( Build . SourcesDirectory ) <nl> - BUILD_DIR : $ ( Build . StagingDirectory ) <nl> + ENVOY_DOCKER_BUILD_DIR : $ ( Build . StagingDirectory ) <nl> BAZEL_BUILD_EXTRA_OPTIONS : " - - config = remote - clang - - config = remote - ci - - jobs = 100 - - curses = no " <nl> - # / / test / integration : echo_integration_test is marked exclusive so it will be run locally , no IPv6 locally in container . <nl> - BAZEL_EXTRA_TEST_OPTIONS : " - - test_filter = - IpVersions / EchoIntegrationTest . * / IPv6 " <nl> BAZEL_REMOTE_CACHE : grpcs : / / remotebuildexecution . googleapis . com <nl> BAZEL_REMOTE_INSTANCE : projects / envoy - ci / instances / default_instance <nl> GCP_SERVICE_ACCOUNT_KEY : $ ( GcpServiceAccountKey ) <nl> + displayName : " Run CI script " <nl> <nl> - bash : | <nl> echo " disk space at end of build : " <nl> df - h <nl> + displayName : " Check disk space at end " <nl> condition : always ( ) <nl> <nl> - task : PublishBuildArtifacts @ 1 <nl> inputs : <nl> pathtoPublish : " $ ( Build . StagingDirectory ) / envoy " <nl> - artifactName : ' envoy ' <nl> + artifactName : $ ( CI_TARGET ) <nl> mmm a / ci / WORKSPACE . filter . example <nl> ppp b / ci / WORKSPACE . filter . example <nl> rules_foreign_cc_dependencies ( ) <nl> load ( " @ io_bazel_rules_go / / go : deps . bzl " , " go_register_toolchains " , " go_rules_dependencies " ) <nl> go_rules_dependencies ( ) <nl> go_register_toolchains ( go_version = GO_VERSION ) <nl> + <nl> + load ( " @ envoy / / bazel / toolchains : rbe_toolchains_config . bzl " , " rbe_toolchains_config " ) <nl> + <nl> + rbe_toolchains_config ( ) <nl> mmm a / ci / run_envoy_docker . sh <nl> ppp b / ci / run_envoy_docker . sh <nl> USER_GROUP = root <nl> <nl> [ [ - f . git ] ] & & [ [ ! - d . git ] ] & & GIT_VOLUME_OPTION = " - v $ ( git rev - parse - - git - common - dir ) : $ ( git rev - parse - - git - common - dir ) " <nl> <nl> + [ [ - t 1 ] ] & & DOCKER_TTY_OPTION = - it <nl> + <nl> mkdir - p " $ { ENVOY_DOCKER_BUILD_DIR } " <nl> # Since we specify an explicit hash , docker - run will pull from the remote repo if missing . <nl> - docker run - - rm - t - i - e HTTP_PROXY = $ { http_proxy } - e HTTPS_PROXY = $ { https_proxy } \ <nl> + docker run - - rm $ { DOCKER_TTY_OPTION } - e HTTP_PROXY = $ { http_proxy } - e HTTPS_PROXY = $ { https_proxy } \ <nl> - u " $ { USER } " : " $ { USER_GROUP } " - v " $ { ENVOY_DOCKER_BUILD_DIR } " : / build $ { GIT_VOLUME_OPTION } \ <nl> - - v " $ PWD " : / source - e NUM_CPUS - - cap - add SYS_PTRACE - - cap - add NET_RAW - - cap - add NET_ADMIN " $ { IMAGE_NAME } " : " $ { IMAGE_ID } " \ <nl> + - e BAZEL_BUILD_EXTRA_OPTIONS - e BAZEL_EXTRA_TEST_OPTIONS - e BAZEL_REMOTE_CACHE \ <nl> + - e BAZEL_REMOTE_INSTANCE - e GCP_SERVICE_ACCOUNT_KEY - e NUM_CPUS \ <nl> + - v " $ PWD " : / source - - cap - add SYS_PTRACE - - cap - add NET_RAW - - cap - add NET_ADMIN " $ { IMAGE_NAME } " : " $ { IMAGE_ID } " \ <nl> / bin / bash - lc " groupadd - - gid $ ( id - g ) - f envoygroup & & useradd - o - - uid $ ( id - u ) - - gid $ ( id - g ) - - no - create - home \ <nl> - - home - dir / source envoybuild & & usermod - a - G pcap envoybuild & & su envoybuild - c \ " cd source & & $ * \ " " <nl>
ci : full IPv6 tests in Azure pipelines ( )
envoyproxy/envoy
b94a964ff8f1481e5d7f348a52b3c1349f1e50e4
2019-07-19T18:16:29Z
mmm a / tools / swift / Immediate . cpp <nl> ppp b / tools / swift / Immediate . cpp <nl> void swift : : REPL ( ASTContext & Context ) { <nl> memcpy ( CurBuffer , Line , LineLen ) ; <nl> <nl> / / Special - case backslash for line continuations in the REPL . <nl> - bool HaveLineContinuation = false ; <nl> if ( LineLen > 1 & & Line [ LineLen - 1 ] = = ' \ n ' & & Line [ LineLen - 2 ] = = ' \ \ ' ) { <nl> - HaveLineContinuation = true ; <nl> + HadLineContinuation = true ; <nl> CurBuffer [ LineLen - 2 ] = ' \ n ' ; <nl> CurBuffer [ LineLen - 1 ] = ' \ 0 ' ; <nl> LineLen - = 1 ; <nl> + } else { <nl> + HadLineContinuation = false ; <nl> } <nl> <nl> / / Enter the line into the line history . <nl> void swift : : REPL ( ASTContext & Context ) { <nl> L . lex ( Tok ) ; <nl> } while ( 1 ) ; <nl> <nl> - if ( BraceCount | | HaveLineContinuation ) <nl> + if ( BraceCount | | HadLineContinuation ) <nl> continue ; <nl> <nl> / / Parse the current line ( s ) . <nl>
Fix repl prompt with ' \ ' continuation . < rdar : / / problem / 11296808 > .
apple/swift
924ef61b7c7fcd9d048678476a5a6e06e3a154e2
2012-04-24T20:39:32Z
mmm a / src / mongo / s / collection_metadata . cpp <nl> ppp b / src / mongo / s / collection_metadata . cpp <nl> namespace mongo { <nl> newShardVersion > _collVersion ? newShardVersion : this - > _collVersion ; <nl> metadata - > fillRanges ( ) ; <nl> <nl> - dassert ( metadata - > isValid ( ) ) ; <nl> + invariant ( metadata - > isValid ( ) ) ; <nl> return metadata . release ( ) ; <nl> } <nl> <nl> namespace mongo { <nl> newShardVersion > _collVersion ? newShardVersion : this - > _collVersion ; <nl> metadata - > fillRanges ( ) ; <nl> <nl> - dassert ( metadata - > isValid ( ) ) ; <nl> + invariant ( metadata - > isValid ( ) ) ; <nl> return metadata . release ( ) ; <nl> } <nl> <nl> namespace mongo { <nl> metadata - > _shardVersion = _shardVersion ; <nl> metadata - > _collVersion = _collVersion ; <nl> <nl> - dassert ( metadata - > isValid ( ) ) ; <nl> + invariant ( metadata - > isValid ( ) ) ; <nl> return metadata . release ( ) ; <nl> } <nl> <nl> namespace mongo { <nl> <nl> metadata - > _pendingMap . insert ( make_pair ( pending . getMin ( ) , pending . getMax ( ) ) ) ; <nl> <nl> - dassert ( metadata - > isValid ( ) ) ; <nl> + invariant ( metadata - > isValid ( ) ) ; <nl> return metadata . release ( ) ; <nl> } <nl> <nl> namespace mongo { <nl> metadata - > _shardVersion > _collVersion ? metadata - > _shardVersion : _collVersion ; <nl> metadata - > fillRanges ( ) ; <nl> <nl> - dassert ( metadata - > isValid ( ) ) ; <nl> + invariant ( metadata - > isValid ( ) ) ; <nl> return metadata . release ( ) ; <nl> } <nl> <nl> namespace mongo { <nl> <nl> metadata - > _chunksMap . insert ( make_pair ( minKey , maxKey ) ) ; <nl> <nl> - dassert ( metadata - > isValid ( ) ) ; <nl> + invariant ( metadata - > isValid ( ) ) ; <nl> return metadata . release ( ) ; <nl> } <nl> <nl> namespace mongo { <nl> } <nl> <nl> bool CollectionMetadata : : isValid ( ) const { <nl> - if ( _shardVersion > _collVersion ) return false ; <nl> - if ( _collVersion . majorVersion ( ) = = 0 ) return false ; <nl> - if ( _collVersion . epoch ( ) ! = _shardVersion . epoch ( ) ) return false ; <nl> + if ( _shardVersion > _collVersion ) <nl> + return false ; <nl> + if ( _collVersion . majorVersion ( ) = = 0 ) <nl> + return false ; <nl> + if ( _collVersion . epoch ( ) ! = _shardVersion . epoch ( ) ) <nl> + return false ; <nl> + <nl> + if ( _shardVersion . majorVersion ( ) > 0 ) { <nl> + / / Must be chunks <nl> + if ( _rangesMap . size ( ) = = 0 | | _chunksMap . size ( ) = = 0 ) <nl> + return false ; <nl> + } <nl> + else { <nl> + / / No chunks <nl> + if ( _shardVersion . minorVersion ( ) > 0 ) <nl> + return false ; <nl> + if ( _rangesMap . size ( ) > 0 | | _chunksMap . size ( ) > 0 ) <nl> + return false ; <nl> + } <nl> + <nl> return true ; <nl> } <nl> <nl> mmm a / src / mongo / s / metadata_loader . cpp <nl> ppp b / src / mongo / s / metadata_loader . cpp <nl> namespace mongo { <nl> if ( oldMetadata - > getCollVersion ( ) . hasEqualEpoch ( epoch ) ) { <nl> <nl> fullReload = false ; <nl> - dassert ( oldMetadata - > isValid ( ) ) ; <nl> + invariant ( oldMetadata - > isValid ( ) ) ; <nl> <nl> versionMap [ shard ] = oldMetadata - > _shardVersion ; <nl> metadata - > _collVersion = oldMetadata - > _collVersion ; <nl> namespace mongo { <nl> metadata - > fillRanges ( ) ; <nl> conn . done ( ) ; <nl> <nl> - dassert ( metadata - > isValid ( ) ) ; <nl> + invariant ( metadata - > isValid ( ) ) ; <nl> return Status : : OK ( ) ; <nl> } <nl> else if ( diffsApplied = = 0 ) { <nl>
SERVER - 16223 invariant not dassert on metadata reload sanity checks
mongodb/mongo
813a2908ed3f35e1e395179983e0f09b0fee8fe5
2014-11-18T20:30:58Z
mmm a / doc / api . rst <nl> ppp b / doc / api . rst <nl> customize the formatted output . <nl> <nl> You can also reuse existing formatters , for example : : <nl> <nl> - enum color { red , green , blue } ; <nl> + enum class color { red , green , blue } ; <nl> <nl> template < > <nl> struct fmt : : formatter < color > : formatter < string_view > { <nl> You can also reuse existing formatters , for example : : <nl> auto format ( color c , FormatContext & ctx ) { <nl> string_view name = " unknown " ; <nl> switch ( c ) { <nl> - case red : name = " red " ; break ; <nl> - case green : name = " green " ; break ; <nl> - case blue : name = " blue " ; break ; <nl> + case color : : red : name = " red " ; break ; <nl> + case color : : green : name = " green " ; break ; <nl> + case color : : blue : name = " blue " ; break ; <nl> } <nl> return formatter < string_view > : : format ( name , ctx ) ; <nl> } <nl>
Changed to use scoped enum
fmtlib/fmt
894b6fac8e67ac06238c5bf48d978ff428b2eb86
2018-09-17T00:28:40Z
mmm a / tools / ports / sdl2 . py <nl> ppp b / tools / ports / sdl2 . py <nl> <nl> <nl> import os <nl> <nl> - TAG = ' version_18 ' <nl> - HASH = ' 3a677c06d693c1568543eeb9179f9211a8c482738dab4400ccbc39aabe0cd1e57085e63ba1c25e9faefda1e06046d3b528298c96bb20c132b7c80e2e0aba972c ' <nl> + TAG = ' version_19 ' <nl> + HASH = ' 5ee4c38ed8372ef1c9bca0d3826279be97bdb6150570b0e2b7c0e3a8c33f446b3ebd5df6385fccf6c25ac0fbb4ab00ed4728b52320951e648e38867cfd154795 ' <nl> SUBDIR = ' SDL2 - ' + TAG <nl> <nl> <nl>
Update SDL to version_19 ( )
emscripten-core/emscripten
a31a155105ba9ceb54edac8aa9dba76496935be5
2020-03-13T20:09:07Z
mmm a / CMakeLists . txt <nl> ppp b / CMakeLists . txt <nl> cmake_dependent_option ( <nl> USE_MKLML " Use MKLML interface in MKL BLAS " ON <nl> " BUILD_CAFFE2 " OFF ) <nl> option ( USE_DISTRIBUTED " Use THD ( distributed ) " OFF ) <nl> - option ( USE_DISTRIBUTED_MW " Use THD ( distributed ) master worker " OFF ) <nl> <nl> # Used when building Caffe2 through setup . py <nl> option ( BUILDING_WITH_TORCH_LIBS " Tell cmake if Caffe2 is being built alongside torch libs " OFF ) <nl> mmm a / setup . py <nl> ppp b / setup . py <nl> <nl> <nl> # Before we run the setup_helpers , let ' s look for NO_ * and WITH_ * <nl> # variables and hotpatch the environment with the USE_ * equivalent <nl> - config_env_vars = [ ' CUDA ' , ' CUDNN ' , ' MKLDNN ' , ' NNPACK ' , ' DISTRIBUTED ' , ' DISTRIBUTED_MW ' , <nl> + config_env_vars = [ ' CUDA ' , ' CUDNN ' , ' MKLDNN ' , ' NNPACK ' , ' DISTRIBUTED ' , <nl> ' SYSTEM_NCCL ' , ' GLOO_IBVERBS ' ] <nl> <nl> <nl> def hotpatch_var ( var ) : <nl> from tools . setup_helpers . generate_code import generate_code <nl> from tools . setup_helpers . ninja_builder import NinjaBuilder , ninja_build_ext <nl> from tools . setup_helpers . dist_check import USE_DISTRIBUTED , \ <nl> - USE_DISTRIBUTED_MW , USE_GLOO_IBVERBS , USE_C10D <nl> + USE_GLOO_IBVERBS , USE_C10D <nl> <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> # Parameters parsed from environment <nl> def build_libs ( libs ) : <nl> build_libs_cmd + = [ ' - - use - mkldnn ' ] <nl> if USE_GLOO_IBVERBS : <nl> build_libs_cmd + = [ ' - - use - gloo - ibverbs ' ] <nl> - if USE_DISTRIBUTED_MW : <nl> - build_libs_cmd + = [ ' - - use - distributed - mw ' ] <nl> if FULL_CAFFE2 : <nl> build_libs_cmd + = [ ' - - full - caffe2 ' ] <nl> <nl> def run ( self ) : <nl> main_sources + = [ <nl> " torch / csrc / distributed / Module . cpp " , <nl> ] <nl> - if USE_DISTRIBUTED_MW : <nl> - main_sources + = [ <nl> - " torch / csrc / distributed / Tensor . cpp " , <nl> - " torch / csrc / distributed / Storage . cpp " , <nl> - ] <nl> - extra_compile_args + = [ ' - DUSE_DISTRIBUTED_MW ' ] <nl> include_dirs + = [ tmp_install_path + " / include / THD " ] <nl> main_link_args + = [ THD_LIB ] <nl> <nl> mmm a / tools / build_pytorch_libs . bat <nl> ppp b / tools / build_pytorch_libs . bat <nl> IF " % ~ 1 " = = " - - use - gloo - ibverbs " ( <nl> set / a USE_GLOO_IBVERBS = 0 <nl> ) <nl> <nl> - IF " % ~ 1 " = = " - - use - distributed - mw " ( <nl> - set / a USE_DISTRIBUTED_MW = 1 <nl> - echo Warning : distributed mw is enabled but build is not yet implemented 1 > & 2 <nl> - shift <nl> - ) ELSE ( <nl> - set / a USE_DISTRIBUTED_MW = 0 <nl> - ) <nl> - <nl> set BUILD_TYPE = Release <nl> IF " % DEBUG % " = = " 1 " ( <nl> set BUILD_TYPE = Debug <nl> mmm a / tools / build_pytorch_libs . sh <nl> ppp b / tools / build_pytorch_libs . sh <nl> USE_ROCM = 0 <nl> USE_NNPACK = 0 <nl> USE_MKLDNN = 0 <nl> USE_GLOO_IBVERBS = 0 <nl> - USE_DISTRIBUTED_MW = 0 <nl> FULL_CAFFE2 = 0 <nl> while [ [ $ # - gt 0 ] ] ; do <nl> case " $ 1 " in <nl> while [ [ $ # - gt 0 ] ] ; do <nl> - - use - gloo - ibverbs ) <nl> USE_GLOO_IBVERBS = 1 <nl> ; ; <nl> - - - use - distributed - mw ) <nl> - USE_DISTRIBUTED_MW = 1 <nl> - ; ; <nl> - - full - caffe2 ) <nl> FULL_CAFFE2 = 1 <nl> ; ; <nl> if [ [ $ USE_GLOO_IBVERBS - eq 1 ] ] ; then <nl> GLOO_FLAGS + = " - DUSE_IBVERBS = 1 - DBUILD_SHARED_LIBS = 1 " <nl> THD_FLAGS = " - DUSE_GLOO_IBVERBS = 1 " <nl> fi <nl> - if [ [ $ USE_DISTRIBUTED_MW - eq 1 ] ] ; then <nl> - THD_FLAGS + = " - DUSE_DISTRIBUTED_MW = 1 " <nl> - fi <nl> CWRAP_FILES = " \ <nl> $ BASE_DIR / torch / lib / ATen / Declarations . cwrap ; \ <nl> $ BASE_DIR / torch / lib / THNN / generic / THNN . h ; \ <nl> mmm a / tools / setup_helpers / dist_check . py <nl> ppp b / tools / setup_helpers / dist_check . py <nl> <nl> <nl> # On ROCm , RCCL development isn ' t complete . https : / / github . com / ROCmSoftwarePlatform / rccl <nl> USE_DISTRIBUTED = not check_negative_env_flag ( " USE_DISTRIBUTED " ) and not IS_WINDOWS and not check_env_flag ( " USE_ROCM " ) <nl> - USE_DISTRIBUTED_MW = USE_DISTRIBUTED and check_env_flag ( " USE_DISTRIBUTED_MW " ) <nl> USE_GLOO_IBVERBS = False <nl> USE_C10D = USE_DISTRIBUTED and USE_CUDA and IS_LINUX <nl> <nl> mmm a / torch / csrc / distributed / Module . cpp <nl> ppp b / torch / csrc / distributed / Module . cpp <nl> static std : : unordered_map < std : : string , THDChannelType > name2channel_type = { <nl> { " nccl " , THDChannelNccl } , <nl> } ; <nl> <nl> - static bool THDPModule_loadClasses ( PyObject * self ) <nl> - { <nl> - # ifdef USE_DISTRIBUTED_MW <nl> - # define ASSERT_NOT_NULL ( ptr ) if ( ! ( ptr ) ) { THPUtils_setError ( " couldn ' t load classes " ) ; return false ; } <nl> - PyObject * torch_module = PyImport_ImportModule ( " torch . distributed " ) ; <nl> - if ( ! torch_module ) { <nl> - THPUtils_setError ( " class loader couldn ' t access torch . distributed module " ) ; <nl> - return false ; <nl> - } <nl> - <nl> - if ( ! THDPDoubleTensor_postInit ( torch_module ) ) return false ; <nl> - if ( ! THDPFloatTensor_postInit ( torch_module ) ) return false ; <nl> - if ( ! THDPHalfTensor_postInit ( torch_module ) ) return false ; <nl> - if ( ! THDPLongTensor_postInit ( torch_module ) ) return false ; <nl> - if ( ! THDPIntTensor_postInit ( torch_module ) ) return false ; <nl> - if ( ! THDPShortTensor_postInit ( torch_module ) ) return false ; <nl> - if ( ! THDPCharTensor_postInit ( torch_module ) ) return false ; <nl> - if ( ! THDPByteTensor_postInit ( torch_module ) ) return false ; <nl> - <nl> - ASSERT_NOT_NULL ( THDPDoubleStorageClass = PyObject_GetAttrString ( torch_module , ( char * ) " DoubleStorage " ) ) ; <nl> - ASSERT_NOT_NULL ( THDPFloatStorageClass = PyObject_GetAttrString ( torch_module , ( char * ) " FloatStorage " ) ) ; <nl> - ASSERT_NOT_NULL ( THDPHalfStorageClass = PyObject_GetAttrString ( torch_module , ( char * ) " HalfStorage " ) ) ; <nl> - ASSERT_NOT_NULL ( THDPLongStorageClass = PyObject_GetAttrString ( torch_module , ( char * ) " LongStorage " ) ) ; <nl> - ASSERT_NOT_NULL ( THDPIntStorageClass = PyObject_GetAttrString ( torch_module , ( char * ) " IntStorage " ) ) ; <nl> - ASSERT_NOT_NULL ( THDPShortStorageClass = PyObject_GetAttrString ( torch_module , ( char * ) " ShortStorage " ) ) ; <nl> - ASSERT_NOT_NULL ( THDPCharStorageClass = PyObject_GetAttrString ( torch_module , ( char * ) " CharStorage " ) ) ; <nl> - ASSERT_NOT_NULL ( THDPByteStorageClass = PyObject_GetAttrString ( torch_module , ( char * ) " ByteStorage " ) ) ; <nl> - <nl> - # undef ASSERT_NOT_NULL <nl> - # endif <nl> - return true ; <nl> - } <nl> - <nl> - static bool THDPModule_assignStateless ( PyObject * self ) <nl> - { <nl> - # ifdef USE_DISTRIBUTED_MW <nl> - # define INIT_STATELESS ( type ) \ <nl> - stateless = PyObject_CallFunctionObjArgs ( ( PyObject * ) & TH_CONCAT_3 ( THDP , type , TensorStatelessType ) , NULL ) ; \ <nl> - if ( ! stateless ) { \ <nl> - return false ; \ <nl> - } \ <nl> - if ( PyObject_SetAttrString ( TH_CONCAT_3 ( THDP , type , TensorClass ) , THP_STATELESS_ATTRIBUTE_NAME , stateless ) = = - 1 ) { \ <nl> - return false ; \ <nl> - } <nl> - PyObject * stateless ; <nl> - INIT_STATELESS ( Double ) ; <nl> - INIT_STATELESS ( Float ) ; <nl> - INIT_STATELESS ( Half ) ; <nl> - INIT_STATELESS ( Long ) ; <nl> - INIT_STATELESS ( Int ) ; <nl> - INIT_STATELESS ( Short ) ; <nl> - INIT_STATELESS ( Char ) ; <nl> - INIT_STATELESS ( Byte ) ; <nl> - # undef INIT_STATELESS <nl> - # endif <nl> - return true ; <nl> - } <nl> - <nl> static std : : unordered_map < PyObject * , THDReduceOp > obj2reduceop ; <nl> static std : : unordered_map < PyObject * , THDGroup > obj2group ; <nl> <nl> PyObject * THDPModule_destroyProcessGroup ( PyObject * _unused ) { <nl> END_HANDLE_TH_ERRORS <nl> } <nl> <nl> - # ifdef USE_DISTRIBUTED_MW <nl> - PyObject * THDPModule_initMasterWorker ( PyObject * _unused , PyObject * args ) <nl> - { <nl> - HANDLE_TH_ERRORS <nl> - if ( PyTuple_GET_SIZE ( args ) ! = 5 | | ! THPUtils_checkString ( PyTuple_GET_ITEM ( args , 0 ) ) | | <nl> - ! THPUtils_checkString ( PyTuple_GET_ITEM ( args , 1 ) ) | | <nl> - ! THPUtils_checkLong ( PyTuple_GET_ITEM ( args , 2 ) ) | | <nl> - ! THPUtils_checkString ( PyTuple_GET_ITEM ( args , 3 ) ) | | <nl> - ! THPUtils_checkLong ( PyTuple_GET_ITEM ( args , 4 ) ) ) { <nl> - THPUtils_invalidArguments ( args , NULL , " init_master_worker " , 1 , " ( string backend , string init_method , int world_size , string group_name , int rank ) " ) ; <nl> - return NULL ; <nl> - } <nl> - <nl> - std : : string backend_name = THPUtils_unpackString ( PyTuple_GET_ITEM ( args , 0 ) ) ; <nl> - std : : string init_method = THPUtils_unpackString ( PyTuple_GET_ITEM ( args , 1 ) ) ; <nl> - int world_size = THPUtils_unpackLong ( PyTuple_GET_ITEM ( args , 2 ) ) ; <nl> - std : : string group_name = THPUtils_unpackString ( PyTuple_GET_ITEM ( args , 3 ) ) ; <nl> - int rank = THPUtils_unpackLong ( PyTuple_GET_ITEM ( args , 4 ) ) ; <nl> - <nl> - THDChannelType channel_type = name2channel_type . at ( backend_name ) ; <nl> - { <nl> - AutoNoGIL nogil ; <nl> - THDMasterWorkerInit ( channel_type , init_method , world_size , group_name , rank ) ; <nl> - } <nl> - # ifdef USE_CUDA <nl> - THDSetCudaStatePtr ( & state ) ; <nl> - # endif <nl> - Py_RETURN_NONE ; <nl> - END_HANDLE_TH_ERRORS <nl> - } <nl> - # endif <nl> - <nl> # ifdef USE_CUDA <nl> PyObject * THDPModule_registerStream ( PyObject * _unused , PyObject * _stream ) <nl> { <nl> PyObject * THDPModule_initExtension ( PyObject * _unused , PyObject * args ) { <nl> # undef REGISTER_GROUP <nl> <nl> if ( is_master_worker ) { <nl> - PyObject * module = PyImport_ImportModule ( " torch . distributed " ) ; <nl> - THPUtils_assert ( module , " class loader couldn ' t access torch . distributed module " ) ; <nl> - PyObject * module_dict = PyModule_GetDict ( module ) ; <nl> - if ( ! THDPModule_loadClasses ( module_dict ) ) return NULL ; <nl> - if ( ! THDPModule_assignStateless ( module_dict ) ) return NULL ; <nl> + throw std : : runtime_error ( " THD master_worker no longer supported " ) ; <nl> } <nl> Py_RETURN_TRUE ; <nl> } <nl> static struct PyMethodDef _THDPModule_methods [ ] = { <nl> { " _dist_init_process_group " , ( PyCFunction ) THDPModule_initProcessGroup , METH_VARARGS , NULL } , <nl> { " _dist_destroy_process_group " , ( PyCFunction ) THDPModule_destroyProcessGroup , METH_NOARGS , NULL } , <nl> { " _dist_clear_group_cache " , ( PyCFunction ) THDPModule_clearGroupCache , METH_VARARGS , NULL } , <nl> - # ifdef USE_DISTRIBUTED_MW <nl> - { " _dist_init_master_worker " , ( PyCFunction ) THDPModule_initMasterWorker , METH_VARARGS , NULL } , <nl> - # endif <nl> # ifdef USE_CUDA <nl> { " _dist_register_stream " , ( PyCFunction ) THDPModule_registerStream , METH_O , NULL } , <nl> # endif <nl> deleted file mode 100644 <nl> index e6b0829e3f07 . . 000000000000 <nl> mmm a / torch / csrc / distributed / Storage . cpp <nl> ppp / dev / null <nl> <nl> - # include " torch / csrc / python_headers . h " <nl> - # include < structmember . h > <nl> - <nl> - # define THP_HOST_HALF <nl> - <nl> - # include < TH / TH . h > <nl> - # include < libshm . h > <nl> - # include " THDP . h " <nl> - # include " torch / csrc / copy_utils . h " <nl> - <nl> - # include " override_macros . h " <nl> - <nl> - # define THD_GENERIC_FILE " torch / csrc / generic / Storage . cpp " <nl> - # include < THD / base / THDGenerateAllTypes . h > <nl> - <nl> - / / # define THD_GENERIC_FILE " torch / csrc / generic / StorageCopy . cpp " <nl> - / / # include < THD / THDGenerateAllTypes . h > <nl> - <nl> deleted file mode 100644 <nl> index 5639efba2e3e . . 000000000000 <nl> mmm a / torch / csrc / distributed / Storage . h <nl> ppp / dev / null <nl> <nl> - # ifndef THDP_STORAGE_INC <nl> - # define THDP_STORAGE_INC <nl> - <nl> - # define THDPStorage TH_CONCAT_3 ( THDP , Real , Storage ) <nl> - # define THDPStorageStr TH_CONCAT_STRING_3 ( torch . cuda . , Real , Storage ) <nl> - # define THDPStorageClass TH_CONCAT_3 ( THDP , Real , StorageClass ) <nl> - # define THDPStorage_ ( NAME ) TH_CONCAT_4 ( THDP , Real , Storage_ , NAME ) <nl> - <nl> - # define THDPDoubleStorage_Check ( obj ) \ <nl> - PyObject_IsInstance ( obj , THDPDoubleStorageClass ) <nl> - # define THDPFloatStorage_Check ( obj ) \ <nl> - PyObject_IsInstance ( obj , THDPFloatStorageClass ) <nl> - # define THDPHalfStorage_Check ( obj ) \ <nl> - PyObject_IsInstance ( obj , THDPHalfStorageClass ) <nl> - # define THDPLongStorage_Check ( obj ) \ <nl> - PyObject_IsInstance ( obj , THDPLongStorageClass ) <nl> - # define THDPIntStorage_Check ( obj ) \ <nl> - PyObject_IsInstance ( obj , THDPIntStorageClass ) <nl> - # define THDPShortStorage_Check ( obj ) \ <nl> - PyObject_IsInstance ( obj , THDPShortStorageClass ) <nl> - # define THDPCharStorage_Check ( obj ) \ <nl> - PyObject_IsInstance ( obj , THDPCharStorageClass ) <nl> - # define THDPByteStorage_Check ( obj ) \ <nl> - PyObject_IsInstance ( obj , THDPByteStorageClass ) <nl> - <nl> - # define THDPDoubleStorage_CData ( obj ) ( obj ) - > cdata <nl> - # define THDPFloatStorage_CData ( obj ) ( obj ) - > cdata <nl> - # define THDPLongStorage_CData ( obj ) ( obj ) - > cdata <nl> - # define THDPIntStorage_CData ( obj ) ( obj ) - > cdata <nl> - # define THDPShortStorage_CData ( obj ) ( obj ) - > cdata <nl> - # define THDPCharStorage_CData ( obj ) ( obj ) - > cdata <nl> - # define THDPByteStorage_CData ( obj ) ( obj ) - > cdata <nl> - <nl> - # ifdef _THP_CORE <nl> - # define THDPStorageType TH_CONCAT_3 ( THDP , Real , StorageType ) <nl> - # define THDPStorageBaseStr TH_CONCAT_STRING_3 ( Distributed , Real , StorageBase ) <nl> - # endif <nl> - <nl> - # include " override_macros . h " <nl> - <nl> - # define THD_GENERIC_FILE " torch / csrc / generic / Storage . h " <nl> - # include < THD / base / THDGenerateAllTypes . h > <nl> - <nl> - # endif <nl> - <nl> mmm a / torch / csrc / distributed / THDP . h <nl> ppp b / torch / csrc / distributed / THDP . h <nl> <nl> <nl> # include " torch / csrc / THP . h " <nl> # include " Module . h " <nl> - # ifdef USE_DISTRIBUTED_MW <nl> - # include " Storage . h " <nl> - # include " . . / PtrWrapper . h " <nl> - # ifdef _THP_CORE <nl> - # include " utils . h " <nl> - # endif <nl> - # endif <nl> <nl> # endif <nl> mmm a / torch / lib / THD / CMakeLists . txt <nl> ppp b / torch / lib / THD / CMakeLists . txt <nl> IF ( NOT THD_INSTALL_BIN_DIR OR NOT THD_INSTALL_LIB_DIR OR NOT THD_INSTALL_INCLUDE <nl> SET ( THD_INSTALL_INCLUDE_DIR " include " CACHE PATH " THD install include subdirectory " ) <nl> ENDIF ( ) <nl> <nl> - FILE ( GLOB_RECURSE master_worker_h RELATIVE $ { CMAKE_CURRENT_SOURCE_DIR } " master_worker / * . h " ) <nl> - FILE ( GLOB_RECURSE master_worker_cpp " master_worker / * . cpp " ) <nl> FILE ( GLOB_RECURSE process_group_h RELATIVE $ { CMAKE_CURRENT_SOURCE_DIR } " process_group / * . h " ) <nl> FILE ( GLOB_RECURSE process_group_cpp " process_group / * . cpp " ) <nl> FILE ( GLOB_RECURSE base_h RELATIVE $ { CMAKE_CURRENT_SOURCE_DIR } " base / * . h " ) <nl> IF ( NOT DISTRIBUTED_NCCL_FOUND ) <nl> LIST ( REMOVE_ITEM base_cpp " $ { CMAKE_CURRENT_SOURCE_DIR } / base / data_channels / DataChannelNccl . cpp " ) <nl> ENDIF ( ) <nl> <nl> - EXCLUDE_DIR ( master_worker_cpp " . * / dispatch / . * \ \ . cpp $ " ) <nl> - <nl> SET ( all_cpp $ { base_cpp } $ { process_group_cpp } ) <nl> SET ( all_h THD . h $ { base_h } $ { process_group_h } ) <nl> <nl> - IF ( USE_DISTRIBUTED_MW ) <nl> - ADD_DEFINITIONS ( - DUSE_DISTRIBUTED_MW = 1 ) <nl> - SET ( all_cpp $ { all_cpp } $ { master_worker_cpp } ) <nl> - SET ( all_h THD . h $ { all_h } $ { master_worker_h } ) <nl> - ENDIF ( ) <nl> - <nl> EXCLUDE_DIR ( all_cpp " . * / generic / . * \ \ . cpp $ " ) <nl> <nl> # Need to include external NCCL first <nl> mmm a / torch / lib / THD / THD . h <nl> ppp b / torch / lib / THD / THD . h <nl> <nl> <nl> # include " process_group / General . h " <nl> # include " process_group / Collectives . h " <nl> - <nl> - # ifdef USE_DISTRIBUTED_MW <nl> - # include " master_worker / master / Master . h " <nl> - # include " master_worker / master / State . h " <nl> - # include " master_worker / master / THDRandom . h " <nl> - # include " master_worker / master / THDStorage . h " <nl> - # include " master_worker / master / THDTensor . h " <nl> - <nl> - # include " master_worker / worker / Worker . h " <nl> - # endif <nl> deleted file mode 100644 <nl> index 6e54181c6d91 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / README . md <nl> ppp / dev / null <nl> @ @ - 1 + 0 , 0 @ @ <nl> - This folder is effectively dead at the moment . <nl> deleted file mode 100644 <nl> index bf342572c628 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / common / ByteArray . cpp <nl> ppp / dev / null <nl> <nl> - # include " ByteArray . hpp " <nl> - <nl> - # include < cstdlib > <nl> - # include < cstddef > <nl> - # include < cstring > <nl> - # include < exception > <nl> - # include < string > <nl> - # include < system_error > <nl> - # include < utility > <nl> - <nl> - namespace thd { namespace rpc { <nl> - <nl> - ByteArray : : ByteArray ( ) <nl> - : _data ( ) <nl> - { } <nl> - <nl> - ByteArray : : ByteArray ( size_t size ) <nl> - : ByteArray ( ) <nl> - { <nl> - _data . reserve ( size ) ; <nl> - } <nl> - <nl> - ByteArray : : ByteArray ( const char * arr , size_t size ) <nl> - : _data ( arr , arr + size ) <nl> - { } <nl> - <nl> - ByteArray : : ByteArray ( ByteArray & & arr ) <nl> - { <nl> - std : : swap ( _data , arr . _data ) ; <nl> - } <nl> - <nl> - ByteArray : : ByteArray ( const ByteArray & arr ) <nl> - : _data ( arr . _data ) <nl> - { } <nl> - <nl> - ByteArray : : ~ ByteArray ( ) { } <nl> - <nl> - ByteArray & ByteArray : : append ( const char * arr , size_t size ) { <nl> - _data . append ( arr , arr + size ) ; <nl> - return * this ; <nl> - } <nl> - <nl> - const char * ByteArray : : data ( ) const { <nl> - return _data . data ( ) ; <nl> - } <nl> - <nl> - size_t ByteArray : : length ( ) const { <nl> - return _data . size ( ) ; <nl> - } <nl> - <nl> - std : : string ByteArray : : to_string ( ) const { <nl> - return _data ; <nl> - } <nl> - <nl> - } } / / namespace rpc , thd <nl> deleted file mode 100644 <nl> index 209922292e4a . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / common / ByteArray . hpp <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include < cstddef > <nl> - # include < string > <nl> - <nl> - namespace thd { namespace rpc { <nl> - <nl> - struct ByteArray { <nl> - using size_type = size_t ; <nl> - <nl> - ByteArray ( ) ; <nl> - ByteArray ( size_t size ) ; <nl> - ByteArray ( const char * arr , size_t size ) ; <nl> - ByteArray ( ByteArray & & arr ) ; <nl> - ByteArray ( const ByteArray & arr ) ; <nl> - ~ ByteArray ( ) ; <nl> - <nl> - ByteArray & append ( const char * arr , size_t size ) ; <nl> - const char * data ( ) const ; <nl> - size_type length ( ) const ; <nl> - <nl> - std : : string to_string ( ) const ; <nl> - <nl> - private : <nl> - std : : string _data ; <nl> - } ; <nl> - <nl> - } } / / namespace rpc , thd <nl> - <nl> deleted file mode 100644 <nl> index 3ebaeba03245 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / common / CommandChannel . cpp <nl> ppp / dev / null <nl> <nl> - # include " CommandChannel . hpp " <nl> - # include " Functions . hpp " <nl> - # include " . . / . . / base / ChannelUtils . hpp " <nl> - <nl> - # include < unistd . h > <nl> - # include < climits > <nl> - # include < cstdlib > <nl> - # include < cstring > <nl> - # include < exception > <nl> - # include < memory > <nl> - # include < string > <nl> - # include < stdexcept > <nl> - # include < utility > <nl> - # include < iostream > <nl> - <nl> - namespace thd { <nl> - namespace { <nl> - <nl> - void sendMessage ( int socket , std : : unique_ptr < rpc : : RPCMessage > msg ) { <nl> - auto & bytes = msg . get ( ) - > bytes ( ) ; <nl> - uint64_t msg_length = static_cast < uint64_t > ( bytes . length ( ) ) ; <nl> - <nl> - send_bytes < uint64_t > ( socket , & msg_length , 1 , true ) ; <nl> - send_bytes < std : : uint8_t > ( <nl> - socket , <nl> - reinterpret_cast < const std : : uint8_t * > ( bytes . data ( ) ) , <nl> - msg_length <nl> - ) ; <nl> - } <nl> - <nl> - std : : unique_ptr < rpc : : RPCMessage > receiveMessage ( int socket ) { <nl> - uint64_t msg_length ; <nl> - recv_bytes < uint64_t > ( socket , & msg_length , 1 ) ; <nl> - <nl> - std : : unique_ptr < std : : uint8_t [ ] > bytes ( new std : : uint8_t [ msg_length ] ) ; <nl> - recv_bytes < std : : uint8_t > ( socket , bytes . get ( ) , msg_length ) ; <nl> - <nl> - return std : : unique_ptr < rpc : : RPCMessage > ( <nl> - new rpc : : RPCMessage ( reinterpret_cast < char * > ( bytes . get ( ) ) , msg_length ) <nl> - ) ; <nl> - } <nl> - <nl> - } / / anonymous namespace <nl> - <nl> - MasterCommandChannel : : MasterCommandChannel ( InitMethod : : Config config ) <nl> - : _rank ( 0 ) <nl> - , _sockets ( config . world_size , - 1 ) <nl> - , _poll_events ( nullptr ) <nl> - , _error_pipe ( - 1 ) <nl> - , _error ( nullptr ) <nl> - , _mutexes ( config . world_size ) <nl> - { <nl> - _sockets [ 0 ] = config . master . listen_socket ; <nl> - } <nl> - <nl> - MasterCommandChannel : : ~ MasterCommandChannel ( ) { <nl> - if ( _error_thread . joinable ( ) ) { <nl> - if ( : : write ( _error_pipe , " exit " , 4 ) ! = 4 ) { <nl> - std : : cerr < < " Failed to notify error thread " < < std : : endl ; <nl> - } <nl> - _error_thread . join ( ) ; <nl> - <nl> - : : close ( _error_pipe ) ; <nl> - } <nl> - <nl> - auto world_size = _sockets . size ( ) ; <nl> - for ( size_t i = 0 ; i < world_size ; + + i ) { <nl> - auto socket = _sockets [ i ] ; <nl> - if ( socket = = - 1 ) continue ; <nl> - try { <nl> - sendMessage ( rpc : : packMessage ( Functions : : exit ) , i ) ; <nl> - } catch ( . . . ) { } <nl> - : : close ( socket ) ; <nl> - } <nl> - <nl> - } <nl> - <nl> - bool MasterCommandChannel : : init ( ) { <nl> - int socket ; <nl> - rank_type rank ; <nl> - for ( size_t i = 1 ; i < _sockets . size ( ) ; + + i ) { <nl> - std : : tie ( socket , std : : ignore ) = accept ( _sockets [ 0 ] ) ; <nl> - recv_bytes < rank_type > ( socket , & rank , 1 ) ; <nl> - _sockets . at ( rank ) = socket ; <nl> - } <nl> - <nl> - / * Sending confirm byte is to test connection and make barrier for workers . <nl> - * It allows to block connected workers until all remaining workers connect . <nl> - * / <nl> - for ( size_t i = 1 ; i < _sockets . size ( ) ; + + i ) { <nl> - std : : uint8_t confirm_byte = 1 ; <nl> - send_bytes < std : : uint8_t > ( _sockets [ i ] , & confirm_byte , 1 ) ; <nl> - } <nl> - <nl> - / / close listen socket <nl> - : : close ( _sockets [ 0 ] ) ; <nl> - <nl> - int fd [ 2 ] ; <nl> - SYSCHECK ( : : pipe ( fd ) ) ; <nl> - _sockets [ 0 ] = fd [ 0 ] ; <nl> - _error_pipe = fd [ 1 ] ; <nl> - _error_thread = std : : thread ( & MasterCommandChannel : : errorHandler , this ) ; <nl> - return true ; <nl> - } <nl> - <nl> - void MasterCommandChannel : : errorHandler ( ) { <nl> - while ( true ) { <nl> - auto error = recvError ( ) ; <nl> - if ( std : : get < 0 > ( error ) = = 0 ) { <nl> - return ; <nl> - } <nl> - <nl> - _error . reset ( new std : : string ( <nl> - " error ( rank " + std : : to_string ( std : : get < 0 > ( error ) ) + " ) : " + std : : get < 1 > ( error ) <nl> - ) ) ; <nl> - } <nl> - } <nl> - <nl> - void MasterCommandChannel : : sendMessage ( std : : unique_ptr < rpc : : RPCMessage > msg , int rank ) { <nl> - / / Throw error received from a worker . <nl> - if ( _error ) { <nl> - throw std : : runtime_error ( * _error ) ; <nl> - } <nl> - <nl> - if ( ( rank < = 0 ) | | ( rank > = _sockets . size ( ) ) ) { <nl> - throw std : : domain_error ( " sendMessage received invalid rank as parameter " ) ; <nl> - } <nl> - <nl> - std : : lock_guard < std : : mutex > guard ( _mutexes [ rank ] ) ; <nl> - : : thd : : sendMessage ( _sockets [ rank ] , std : : move ( msg ) ) ; <nl> - } <nl> - <nl> - std : : tuple < rank_type , std : : string > MasterCommandChannel : : recvError ( ) { <nl> - if ( ! _poll_events ) { <nl> - / / cache poll events array , it will be reused in another ` receiveError ` calls <nl> - _poll_events . reset ( new struct pollfd [ _sockets . size ( ) ] ) ; <nl> - for ( size_t rank = 0 ; rank < _sockets . size ( ) ; + + rank ) { <nl> - _poll_events [ rank ] = { <nl> - . fd = _sockets [ rank ] , <nl> - . events = POLLIN <nl> - } ; <nl> - } <nl> - } <nl> - <nl> - for ( size_t rank = 0 ; rank < _sockets . size ( ) ; + + rank ) { <nl> - _poll_events [ rank ] . revents = 0 ; <nl> - } <nl> - <nl> - SYSCHECK ( : : poll ( _poll_events . get ( ) , _sockets . size ( ) , - 1 ) ) <nl> - for ( size_t rank = 0 ; rank < _sockets . size ( ) ; + + rank ) { <nl> - if ( this - > _poll_events [ rank ] . revents = = 0 ) <nl> - continue ; <nl> - <nl> - if ( rank = = 0 ) { / / we are notified by master to end <nl> - return std : : make_tuple ( 0 , " " ) ; <nl> - } <nl> - <nl> - if ( _poll_events [ rank ] . revents ^ POLLIN ) { <nl> - _poll_events [ rank ] . fd = - 1 ; / / mark worker as ignored <nl> - return std : : make_tuple ( rank , " connection with worker has been closed " ) ; <nl> - } <nl> - <nl> - try { <nl> - / / receive error <nl> - uint64_t error_length ; <nl> - recv_bytes < uint64_t > ( _poll_events [ rank ] . fd , & error_length , 1 ) ; <nl> - <nl> - std : : unique_ptr < char [ ] > error ( new char [ error_length ] ) ; <nl> - recv_bytes < char > ( _poll_events [ rank ] . fd , error . get ( ) , error_length ) ; <nl> - return std : : make_tuple ( rank , std : : string ( error . get ( ) , error_length ) ) ; <nl> - } catch ( const std : : exception & e ) { <nl> - return std : : make_tuple ( rank , " recv : " + std : : string ( e . what ( ) ) ) ; <nl> - } <nl> - } <nl> - <nl> - / / We did not receive error from any worker despite being notified . <nl> - return std : : make_tuple ( 0 , " failed to receive error from worker " ) ; <nl> - } <nl> - <nl> - <nl> - WorkerCommandChannel : : WorkerCommandChannel ( InitMethod : : Config config ) <nl> - : _rank ( config . rank ) <nl> - , _socket ( - 1 ) <nl> - , _master_addr ( config . worker . master_addr ) <nl> - , _master_port ( config . worker . master_port ) <nl> - { } <nl> - <nl> - WorkerCommandChannel : : ~ WorkerCommandChannel ( ) { <nl> - if ( _socket ! = - 1 ) <nl> - : : close ( _socket ) ; <nl> - } <nl> - <nl> - bool WorkerCommandChannel : : init ( ) { <nl> - _socket = connect ( _master_addr , _master_port ) ; <nl> - send_bytes < rank_type > ( _socket , & _rank , 1 ) ; / / send rank <nl> - <nl> - std : : uint8_t confirm_byte ; <nl> - recv_bytes < std : : uint8_t > ( _socket , & confirm_byte , 1 ) ; <nl> - return true ; <nl> - } <nl> - <nl> - std : : unique_ptr < rpc : : RPCMessage > WorkerCommandChannel : : recvMessage ( ) { <nl> - return : : thd : : receiveMessage ( _socket ) ; <nl> - } <nl> - <nl> - void WorkerCommandChannel : : sendError ( const std : : string & error ) { <nl> - uint64_t error_length = static_cast < uint64_t > ( error . size ( ) ) ; <nl> - send_bytes < uint64_t > ( _socket , & error_length , 1 , true ) ; <nl> - send_bytes < char > ( _socket , error . data ( ) , error_length ) ; <nl> - } <nl> - <nl> - } / / namespace thd <nl> deleted file mode 100644 <nl> index c169076e2dac . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / common / CommandChannel . hpp <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include " RPC . hpp " <nl> - <nl> - # include < sys / poll . h > <nl> - # include < atomic > <nl> - # include < memory > <nl> - # include < mutex > <nl> - # include < string > <nl> - # include < thread > <nl> - # include < tuple > <nl> - # include < vector > <nl> - <nl> - namespace thd { <nl> - <nl> - struct MasterCommandChannel { <nl> - MasterCommandChannel ( InitMethod : : Config config ) ; <nl> - ~ MasterCommandChannel ( ) ; <nl> - <nl> - bool init ( ) ; <nl> - <nl> - void sendMessage ( std : : unique_ptr < rpc : : RPCMessage > msg , int rank ) ; <nl> - <nl> - private : <nl> - std : : tuple < rank_type , std : : string > recvError ( ) ; <nl> - void errorHandler ( ) ; <nl> - <nl> - rank_type _rank ; <nl> - std : : vector < int > _sockets ; <nl> - std : : unique_ptr < struct pollfd [ ] > _poll_events ; <nl> - <nl> - int _error_pipe ; / / informs error handler thread that we are exiting <nl> - std : : unique_ptr < std : : string > _error ; <nl> - std : : thread _error_thread ; <nl> - std : : vector < std : : mutex > _mutexes ; <nl> - } ; <nl> - <nl> - struct WorkerCommandChannel { <nl> - WorkerCommandChannel ( InitMethod : : Config config ) ; <nl> - ~ WorkerCommandChannel ( ) ; <nl> - <nl> - bool init ( ) ; <nl> - <nl> - std : : unique_ptr < rpc : : RPCMessage > recvMessage ( ) ; <nl> - void sendError ( const std : : string & error ) ; <nl> - <nl> - private : <nl> - rank_type _rank ; <nl> - int _socket ; <nl> - <nl> - std : : string _master_addr ; <nl> - port_type _master_port ; <nl> - } ; <nl> - <nl> - } / / namespace thd <nl> deleted file mode 100644 <nl> index 71f934678027 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / common / Functions . hpp <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include < cstdint > <nl> - <nl> - namespace thd { <nl> - <nl> - enum Functions : std : : uint16_t { <nl> - / / generator functions <nl> - generatorNew , <nl> - generatorCopy , <nl> - generatorFree , <nl> - generatorSeed , <nl> - generatorManualSeed , <nl> - <nl> - tensorCopyFromMaster , <nl> - tensorCopyFromWorker , <nl> - <nl> - tensorNew , <nl> - tensorNewWithTensor , <nl> - tensorNewWithSize , <nl> - tensorNewWithSize1d , <nl> - tensorNewWithSize2d , <nl> - tensorNewWithSize3d , <nl> - tensorNewWithSize4d , <nl> - tensorNewWithStorage , <nl> - tensorNewWithStorage1d , <nl> - tensorNewWithStorage2d , <nl> - tensorNewWithStorage3d , <nl> - tensorNewWithStorage4d , <nl> - tensorNewClone , <nl> - tensorNewContiguous , <nl> - tensorNewSelect , <nl> - tensorNewNarrow , <nl> - tensorNewTranspose , <nl> - tensorNewUnfold , <nl> - tensorFree , <nl> - tensorResize , <nl> - tensorResizeAs , <nl> - tensorResize1d , <nl> - tensorResize2d , <nl> - tensorResize3d , <nl> - tensorResize4d , <nl> - tensorResize5d , <nl> - tensorSet , <nl> - tensorSetStorage , <nl> - tensorSetStorage1d , <nl> - tensorSetStorage2d , <nl> - tensorSetStorage3d , <nl> - tensorSetStorage4d , <nl> - tensorNarrow , <nl> - tensorSelect , <nl> - tensorTranspose , <nl> - tensorUnfold , <nl> - tensorSqueeze , <nl> - tensorSqueeze1d , <nl> - tensorNElement , <nl> - <nl> - tensorGesv , <nl> - tensorTrtrs , <nl> - tensorGels , <nl> - tensorSyev , <nl> - tensorGeev , <nl> - tensorGesvd , <nl> - tensorGesvd2 , <nl> - tensorGetri , <nl> - tensorPotrf , <nl> - tensorPotrs , <nl> - tensorPotri , <nl> - tensorQr , <nl> - tensorGeqrf , <nl> - tensorOrgqr , <nl> - tensorOrmqr , <nl> - tensorPstrf , <nl> - <nl> - tensorFill , <nl> - tensorMaskedFill , <nl> - tensorMaskedCopy , <nl> - tensorMaskedSelect , <nl> - tensorNonzero , <nl> - tensorIndexSelect , <nl> - tensorIndexCopy , <nl> - tensorIndexAdd , <nl> - tensorIndexFill , <nl> - tensorGather , <nl> - tensorScatter , <nl> - tensorScatterFill , <nl> - tensorDot , <nl> - tensorMinall , <nl> - tensorMaxall , <nl> - tensorMedianall , <nl> - tensorSumall , <nl> - tensorProdall , <nl> - tensorNeg , <nl> - tensorCinv , <nl> - tensorAdd , <nl> - tensorSub , <nl> - tensorMul , <nl> - tensorDiv , <nl> - tensorFmod , <nl> - tensorRemainder , <nl> - tensorClamp , <nl> - tensorCadd , <nl> - tensorCsub , <nl> - tensorCmul , <nl> - tensorCpow , <nl> - tensorCdiv , <nl> - tensorCfmod , <nl> - tensorCremainder , <nl> - tensorAddcmul , <nl> - tensorAddcdiv , <nl> - tensorAddmv , <nl> - tensorAddmm , <nl> - tensorAddr , <nl> - tensorAddbmm , <nl> - tensorBaddbmm , <nl> - tensorMatch , <nl> - tensorNumel , <nl> - tensorMax , <nl> - tensorMin , <nl> - tensorKthvalue , <nl> - tensorMode , <nl> - tensorMedian , <nl> - tensorSum , <nl> - tensorProd , <nl> - tensorCumsum , <nl> - tensorCumprod , <nl> - tensorSign , <nl> - tensorTrace , <nl> - tensorCross , <nl> - tensorCmax , <nl> - tensorCmin , <nl> - tensorCmaxValue , <nl> - tensorCminValue , <nl> - tensorDiag , <nl> - tensorEye , <nl> - tensorRange , <nl> - tensorRandperm , <nl> - tensorReshape , <nl> - tensorSort , <nl> - tensorTopk , <nl> - tensorTril , <nl> - tensorTriu , <nl> - tensorCatArray , <nl> - tensorEqual , <nl> - tensorLtValue , <nl> - tensorLeValue , <nl> - tensorGtValue , <nl> - tensorGeValue , <nl> - tensorNeValue , <nl> - tensorEqValue , <nl> - tensorLtValueT , <nl> - tensorLeValueT , <nl> - tensorGtValueT , <nl> - tensorGeValueT , <nl> - tensorNeValueT , <nl> - tensorEqValueT , <nl> - tensorLtTensor , <nl> - tensorLeTensor , <nl> - tensorGtTensor , <nl> - tensorGeTensor , <nl> - tensorNeTensor , <nl> - tensorEqTensor , <nl> - tensorLtTensorT , <nl> - tensorLeTensorT , <nl> - tensorGtTensorT , <nl> - tensorGeTensorT , <nl> - tensorNeTensorT , <nl> - tensorEqTensorT , <nl> - tensorAbs , <nl> - tensorSigmoid , <nl> - tensorLog , <nl> - tensorLog10 , <nl> - tensorLog1p , <nl> - tensorLog2 , <nl> - tensorExp , <nl> - tensorExpm1 , <nl> - tensorCos , <nl> - tensorAcos , <nl> - tensorCosh , <nl> - tensorSin , <nl> - tensorAsin , <nl> - tensorSinh , <nl> - tensorTan , <nl> - tensorAtan , <nl> - tensorAtan2 , <nl> - tensorTanh , <nl> - tensorPow , <nl> - tensorTpow , <nl> - tensorSqrt , <nl> - tensorRsqrt , <nl> - tensorCeil , <nl> - tensorFloor , <nl> - tensorRound , <nl> - tensorTrunc , <nl> - tensorFrac , <nl> - tensorLerp , <nl> - tensorMean , <nl> - tensorStd , <nl> - tensorVar , <nl> - tensorNorm , <nl> - tensorRenorm , <nl> - tensorDist , <nl> - tensorHistc , <nl> - tensorBhistc , <nl> - tensorMeanall , <nl> - tensorVarall , <nl> - tensorStdall , <nl> - tensorNormall , <nl> - tensorLinspace , <nl> - tensorLogspace , <nl> - tensorRand , <nl> - tensorRandn , <nl> - tensorLogicalAndAll , <nl> - tensorLogicalAnd , <nl> - tensorLogicalAnyAll , <nl> - tensorLogicalAny , <nl> - <nl> - / / th_random <nl> - tensorRandom , <nl> - tensorGeometric , <nl> - tensorBernoulli , <nl> - tensorBernoulli_FloatTensor , <nl> - tensorBernoulli_DoubleTensor , <nl> - tensorUniform , <nl> - tensorNormal , <nl> - tensorExponential , <nl> - tensorCauchy , <nl> - tensorLogNormal , <nl> - tensorMultinomial , <nl> - <nl> - / / storage functions <nl> - storageSet , <nl> - storageGet , <nl> - <nl> - storageNew , <nl> - storageNewWithSize , <nl> - storageNewWithSize1 , <nl> - storageNewWithSize2 , <nl> - storageNewWithSize3 , <nl> - storageNewWithSize4 , <nl> - <nl> - storageFree , <nl> - storageResize , <nl> - storageFill , <nl> - <nl> - / / communication requests <nl> - sendTensor , <nl> - sendStorage , <nl> - <nl> - exit <nl> - } ; <nl> - <nl> - } / / namespace thd <nl> deleted file mode 100644 <nl> index 5885b8350504 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / common / RPC - inl . hpp <nl> ppp / dev / null <nl> <nl> - # include < cstdint > <nl> - # include " TH / THStorageFunctions . h " <nl> - # include " Traits . hpp " <nl> - <nl> - namespace thd { namespace rpc { namespace detail { <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - <nl> - constexpr size_t INITIAL_BUFFER_SIZE = 256 ; <nl> - <nl> - template < typename real , <nl> - typename = typename std : : enable_if < std : : is_arithmetic < real > : : value > : : type > <nl> - inline void _appendScalar ( ByteArray & str , real data ) { <nl> - str . append ( reinterpret_cast < char * > ( & data ) , sizeof ( data ) ) ; <nl> - } <nl> - <nl> - inline void _appendType ( ByteArray & str , RPCType _type ) { <nl> - char type = static_cast < char > ( _type ) ; <nl> - str . append ( & type , sizeof ( type ) ) ; <nl> - } <nl> - <nl> - template < typename T > <nl> - inline void __appendData ( ByteArray & str , const T & arg , <nl> - std : : false_type is_generator , std : : false_type is_tensor , std : : false_type is_storage ) { <nl> - _appendType ( str , type_traits < T > : : type ) ; <nl> - _appendScalar < T > ( str , arg ) ; <nl> - } <nl> - <nl> - template < typename T > <nl> - inline void __appendData ( ByteArray & str , const T & arg , <nl> - std : : true_type is_generator , std : : false_type is_tensor , std : : false_type is_storage ) { <nl> - _appendType ( str , RPCType : : GENERATOR ) ; <nl> - _appendScalar < object_id_type > ( str , arg - > generator_id ) ; <nl> - } <nl> - <nl> - template < typename T > <nl> - inline void __appendData ( ByteArray & str , const T & arg , <nl> - std : : false_type is_generator , std : : true_type is_tensor , std : : false_type is_storage ) { <nl> - _appendType ( str , RPCType : : TENSOR ) ; <nl> - _appendScalar < object_id_type > ( str , arg - > tensor_id ) ; <nl> - } <nl> - <nl> - template < typename T > <nl> - inline void __appendData ( ByteArray & str , const T & arg , <nl> - std : : false_type is_generator , std : : false_type is_tensor , std : : true_type is_storage ) { <nl> - _appendType ( str , RPCType : : STORAGE ) ; <nl> - _appendScalar < object_id_type > ( str , arg - > storage_id ) ; <nl> - } <nl> - <nl> - template < typename T > <nl> - inline void _appendData ( ByteArray & str , const T & arg ) { <nl> - __appendData ( <nl> - str , <nl> - arg , <nl> - is_any_of < T , THDGeneratorPtrTypes > ( ) , <nl> - is_any_of < T , THDTensorPtrTypes > ( ) , <nl> - is_any_of < T , THDStoragePtrTypes > ( ) <nl> - ) ; <nl> - } <nl> - <nl> - inline void _appendData ( ByteArray & str , THLongStorage * arg ) { <nl> - _appendType ( str , RPCType : : LONG_STORAGE ) ; <nl> - _appendScalar < char > ( str , arg = = NULL ) ; <nl> - if ( ! arg ) return ; <nl> - _appendScalar < ptrdiff_t > ( str , THLongStorage_size ( arg ) ) ; <nl> - for ( ptrdiff_t i = 0 ; i < THLongStorage_size ( arg ) ; i + + ) <nl> - _appendScalar < int64_t > ( str , THLongStorage_get ( arg , i ) ) ; <nl> - } <nl> - <nl> - template < typename T > <nl> - inline void _appendData ( ByteArray & str , const std : : vector < T > & arg ) { <nl> - int l = arg . size ( ) ; <nl> - _appendData ( str , l ) ; <nl> - for ( size_t i = 0 ; i < l ; i + + ) <nl> - __appendData ( <nl> - str , <nl> - arg [ i ] , <nl> - is_any_of < T , THDGeneratorPtrTypes > ( ) , <nl> - is_any_of < T , THDTensorPtrTypes > ( ) , <nl> - is_any_of < T , THDStoragePtrTypes > ( ) <nl> - ) ; <nl> - } <nl> - <nl> - inline void _appendData ( ByteArray & str , RPCType type ) { <nl> - _appendType ( str , type ) ; <nl> - } <nl> - <nl> - inline void _packIntoString ( ByteArray & str ) { } ; <nl> - <nl> - template < typename T , typename . . . Args > <nl> - inline void _packIntoString ( ByteArray & str , const T & arg , const Args & . . . args ) { <nl> - _appendData ( str , arg ) ; <nl> - _packIntoString ( str , args . . . ) ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - } / / namespace detail <nl> - <nl> - template < typename . . . Args > <nl> - inline std : : unique_ptr < RPCMessage > packMessage ( <nl> - function_id_type fid , <nl> - const Args & . . . args <nl> - ) { <nl> - ByteArray msg ( detail : : INITIAL_BUFFER_SIZE ) ; <nl> - detail : : _appendScalar < function_id_type > ( msg , fid ) ; <nl> - detail : : _packIntoString ( msg , args . . . ) ; <nl> - return std : : unique_ptr < RPCMessage > ( new RPCMessage ( std : : move ( msg ) ) ) ; <nl> - } <nl> - <nl> - } } / / namespace rpc , thd <nl> deleted file mode 100644 <nl> index 9a6a187b0f22 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / common / RPC . cpp <nl> ppp / dev / null <nl> <nl> - # include " RPC . hpp " <nl> - # include " ByteArray . hpp " <nl> - <nl> - # include < cstdarg > <nl> - # include < cstring > <nl> - # include < iostream > <nl> - # include < memory > <nl> - # include < stdexcept > <nl> - <nl> - namespace thd { <nl> - namespace rpc { <nl> - <nl> - RPCMessage : : RPCMessage ( ) <nl> - : _msg ( 0 ) <nl> - , _offset ( 0 ) <nl> - { } <nl> - <nl> - RPCMessage : : RPCMessage ( char * str , size_t size ) <nl> - : _msg ( str , size ) <nl> - , _offset ( 0 ) <nl> - { } <nl> - <nl> - RPCMessage : : RPCMessage ( const ByteArray & str ) <nl> - : _msg ( str ) <nl> - , _offset ( 0 ) <nl> - { } <nl> - <nl> - RPCMessage : : RPCMessage ( ByteArray & & str ) <nl> - : _msg ( std : : move ( str ) ) <nl> - , _offset ( 0 ) <nl> - { } <nl> - <nl> - ByteArray & RPCMessage : : bytes ( ) { <nl> - return _msg ; <nl> - } <nl> - <nl> - const char * RPCMessage : : data ( ) const { <nl> - return _msg . data ( ) + _offset ; <nl> - } <nl> - <nl> - bool RPCMessage : : isEmpty ( ) const { <nl> - return _offset > = _msg . length ( ) ; <nl> - } <nl> - <nl> - RPCMessage : : size_type RPCMessage : : remaining ( ) const { <nl> - return _msg . length ( ) - _offset ; <nl> - } <nl> - <nl> - const char * RPCMessage : : read ( size_t num_bytes ) { <nl> - if ( _offset + num_bytes > _msg . length ( ) ) <nl> - throw std : : out_of_range ( " invalid access : out of bounds " ) ; <nl> - const char * ret_val = _msg . data ( ) + _offset ; <nl> - _offset + = num_bytes ; <nl> - return ret_val ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - <nl> - namespace { <nl> - <nl> - template < typename T > <nl> - inline T unpackScalar ( RPCMessage & raw_message ) { <nl> - return * reinterpret_cast < const T * > ( raw_message . read ( sizeof ( T ) ) ) ; <nl> - } <nl> - <nl> - } / / namespace <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - <nl> - static_assert ( sizeof ( RPCType ) = = sizeof ( char ) , " RPCType has to be of the " <nl> - " same size as char " ) ; <nl> - RPCType unpackType ( RPCMessage & raw_message ) { <nl> - char _type = * raw_message . read ( sizeof ( RPCType ) ) ; <nl> - return static_cast < RPCType > ( _type ) ; <nl> - } <nl> - <nl> - RPCType peekType ( RPCMessage & raw_message ) { <nl> - char _type = * raw_message . data ( ) ; <nl> - return static_cast < RPCType > ( _type ) ; <nl> - } <nl> - <nl> - function_id_type unpackFunctionId ( RPCMessage & raw_message ) { <nl> - return unpackScalar < function_id_type > ( raw_message ) ; <nl> - } <nl> - <nl> - double unpackFloat ( RPCMessage & raw_message ) { <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - if ( type = = RPCType : : DOUBLE ) <nl> - return unpackScalar < double > ( raw_message ) ; <nl> - else if ( type = = RPCType : : FLOAT ) <nl> - return unpackScalar < float > ( raw_message ) ; <nl> - <nl> - throw std : : invalid_argument ( " wrong real type in the raw message " ) ; <nl> - } <nl> - <nl> - int64_t unpackInteger ( RPCMessage & raw_message ) { <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - if ( type = = RPCType : : CHAR ) <nl> - return unpackScalar < int8_t > ( raw_message ) ; <nl> - else if ( type = = RPCType : : SHORT ) <nl> - return unpackScalar < int16_t > ( raw_message ) ; <nl> - else if ( type = = RPCType : : INT ) <nl> - return unpackScalar < int32_t > ( raw_message ) ; <nl> - else if ( type = = RPCType : : LONG ) <nl> - return unpackScalar < int64_t > ( raw_message ) ; <nl> - else if ( type = = RPCType : : LONG_LONG ) <nl> - return unpackScalar < int64_t > ( raw_message ) ; <nl> - <nl> - throw std : : invalid_argument ( std : : string ( " wrong integer type in the raw message ( " ) + <nl> - std : : to_string ( static_cast < char > ( type ) ) + " ) " ) ; <nl> - } <nl> - <nl> - object_id_type unpackTensor ( RPCMessage & raw_message ) { <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - if ( type = = RPCType : : TENSOR ) <nl> - return unpackScalar < object_id_type > ( raw_message ) ; <nl> - throw std : : invalid_argument ( " expected tensor in the raw message " ) ; <nl> - } <nl> - <nl> - object_id_type unpackStorage ( RPCMessage & raw_message ) { <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - if ( type = = RPCType : : STORAGE ) <nl> - return unpackScalar < object_id_type > ( raw_message ) ; <nl> - throw std : : invalid_argument ( " expected storage in the raw message " ) ; <nl> - } <nl> - <nl> - object_id_type unpackGenerator ( RPCMessage & raw_message ) { <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - if ( type = = RPCType : : GENERATOR ) { <nl> - return unpackScalar < object_id_type > ( raw_message ) ; <nl> - } <nl> - throw std : : invalid_argument ( " expected generator in the raw message " ) ; <nl> - } <nl> - <nl> - THLongStorage * unpackTHLongStorage ( RPCMessage & raw_message ) { <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - if ( type ! = RPCType : : LONG_STORAGE ) <nl> - throw std : : invalid_argument ( " expected THLongStorage in the raw message " ) ; <nl> - char is_null = unpackScalar < char > ( raw_message ) ; <nl> - if ( is_null ) return NULL ; <nl> - ptrdiff_t size = unpackScalar < ptrdiff_t > ( raw_message ) ; <nl> - THLongStorage * storage = THLongStorage_newWithSize ( size ) ; <nl> - int64_t * data = THLongStorage_data ( storage ) ; <nl> - <nl> - try { <nl> - for ( int i = 0 ; i < size ; i + + ) { <nl> - data [ i ] = unpackScalar < int64_t > ( raw_message ) ; <nl> - } <nl> - } catch ( std : : exception & e ) { <nl> - THLongStorage_free ( storage ) ; <nl> - throw ; <nl> - } <nl> - <nl> - return storage ; <nl> - } <nl> - <nl> - } } / / namespace rpc , thd <nl> deleted file mode 100644 <nl> index 99b45942b0a7 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / common / RPC . hpp <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - # include " . . / master / THDTensor . h " <nl> - # include " ByteArray . hpp " <nl> - # include " TH / THStorageFunctions . h " <nl> - # include " RPCType . hpp " <nl> - <nl> - # include < cstdint > <nl> - # include < memory > <nl> - # include < string > <nl> - <nl> - namespace thd { <nl> - <nl> - using object_id_type = uint64_t ; <nl> - <nl> - namespace rpc { <nl> - <nl> - using function_id_type = uint16_t ; <nl> - <nl> - class RPCMessage { <nl> - public : <nl> - using size_type = ByteArray : : size_type ; <nl> - RPCMessage ( ) ; <nl> - RPCMessage ( char * str , size_t size ) ; <nl> - RPCMessage ( const ByteArray & str ) ; <nl> - RPCMessage ( ByteArray & & str ) ; <nl> - <nl> - ByteArray & bytes ( ) ; / / Raw data . <nl> - const char * data ( ) const ; / / Offset data . <nl> - bool isEmpty ( ) const ; <nl> - size_type remaining ( ) const ; / / Length of the msg left to read . <nl> - const char * read ( size_t num_bytes ) ; <nl> - <nl> - private : <nl> - ByteArray _msg ; <nl> - size_t _offset ; <nl> - } ; <nl> - <nl> - template < typename . . . Args > <nl> - std : : unique_ptr < RPCMessage > packMessage ( function_id_type fid , const Args & . . . args ) ; <nl> - <nl> - RPCType unpackType ( RPCMessage & raw_message ) ; <nl> - RPCType peekType ( RPCMessage & raw_message ) ; <nl> - double unpackFloat ( RPCMessage & raw_message ) ; <nl> - function_id_type unpackFunctionId ( RPCMessage & raw_message ) ; <nl> - int64_t unpackInteger ( RPCMessage & raw_message ) ; <nl> - object_id_type unpackGenerator ( RPCMessage & raw_message ) ; <nl> - object_id_type unpackTensor ( RPCMessage & raw_message ) ; <nl> - object_id_type unpackStorage ( RPCMessage & raw_message ) ; <nl> - THLongStorage * unpackTHLongStorage ( RPCMessage & raw_message ) ; <nl> - <nl> - } } / / namespace rpc , thd <nl> - <nl> - # include " RPC - inl . hpp " <nl> deleted file mode 100644 <nl> index ada83d242e75 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / common / Traits . hpp <nl> ppp / dev / null <nl> <nl> - # include < type_traits > <nl> - # include < tuple > <nl> - <nl> - # include " master_worker / master / THDTensor . h " <nl> - # include " master_worker / master / THDStorage . h " <nl> - <nl> - namespace thd { <nl> - <nl> - template < typename . . . > <nl> - struct or_trait : std : : false_type { } ; <nl> - <nl> - template < typename T > <nl> - struct or_trait < T > : T { } ; <nl> - <nl> - template < typename T , typename . . . Ts > <nl> - struct or_trait < T , Ts . . . > <nl> - : std : : conditional < T : : value , T , or_trait < Ts . . . > > : : type { } ; <nl> - <nl> - template < typename T , typename U > <nl> - struct is_any_of : std : : false_type { } ; <nl> - <nl> - template < typename T , typename U > <nl> - struct is_any_of < T , std : : tuple < U > > : std : : is_same < T , U > { } ; <nl> - <nl> - template < typename T , typename Head , typename . . . Tail > <nl> - struct is_any_of < T , std : : tuple < Head , Tail . . . > > <nl> - : or_trait < std : : is_same < T , Head > , is_any_of < T , std : : tuple < Tail . . . > > > { } ; <nl> - <nl> - using THDGeneratorTypes = std : : tuple < THDGenerator > ; <nl> - <nl> - using THDTensorTypes = std : : tuple < <nl> - THDByteTensor , <nl> - THDCharTensor , <nl> - THDShortTensor , <nl> - THDIntTensor , <nl> - THDLongTensor , <nl> - THDFloatTensor , <nl> - THDDoubleTensor <nl> - > ; <nl> - <nl> - using THDStorageTypes = std : : tuple < <nl> - THDByteStorage , <nl> - THDCharStorage , <nl> - THDShortStorage , <nl> - THDIntStorage , <nl> - THDLongStorage , <nl> - THDFloatStorage , <nl> - THDDoubleStorage <nl> - > ; <nl> - <nl> - template < template < typename > class Trait , typename U > <nl> - struct map_to_ptr { } ; <nl> - <nl> - template < template < typename > class Trait , typename . . . Types > <nl> - struct map_to_ptr < Trait , std : : tuple < Types . . . > > { <nl> - using type = std : : tuple < <nl> - typename std : : add_pointer < Types > : : type . . . , <nl> - typename std : : add_pointer < typename Trait < Types > : : type > : : type . . . <nl> - > ; <nl> - } ; <nl> - <nl> - using THDGeneratorPtrTypes = map_to_ptr < std : : add_const , THDGeneratorTypes > : : type ; <nl> - using THDTensorPtrTypes = map_to_ptr < std : : add_const , THDTensorTypes > : : type ; <nl> - using THDStoragePtrTypes = map_to_ptr < std : : add_const , THDStorageTypes > : : type ; <nl> - <nl> - } / / namespace thd <nl> deleted file mode 100644 <nl> index 87c81cf5fc17 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / Master . cpp <nl> ppp / dev / null <nl> <nl> - # include " Master . h " <nl> - # include " Master . hpp " <nl> - # include " State . hpp " <nl> - # include " . . / worker / Worker . h " <nl> - # include " . . / . . / process_group / General . hpp " <nl> - # include " . . / . . / base / Exceptions . hpp " <nl> - <nl> - namespace thd { <nl> - namespace master { <nl> - <nl> - std : : unique_ptr < MasterCommandChannel > masterCommandChannel ; <nl> - <nl> - } / / namespace master <nl> - } / / namespace thd <nl> - <nl> - using namespace thd ; <nl> - using namespace thd : : master ; <nl> - <nl> - void THDMasterWorkerInit ( THDChannelType channel_type , std : : string init_method = " env : / / " , <nl> - int world_size = - 1 , std : : string group_name = " " , <nl> - int rank = - 1 ) { <nl> - HANDLE_EXCEPTIONS <nl> - THDProcessGroupInit ( channel_type , init_method , world_size , group_name , rank ) ; <nl> - <nl> - if ( dataChannel - > getRank ( ) > 0 ) { <nl> - / * <nl> - * Worker initialization . It goes into infinite loop in which waits <nl> - * for commands from master . Returning from ` THDWorkerMain ` indicates <nl> - * a failure so it will ` return false ` . <nl> - * / <nl> - THDWorkerMain ( init_method , world_size , group_name , dataChannel - > getRank ( ) ) ; <nl> - THError ( " unexpected exit from worker main loop " ) ; <nl> - } <nl> - <nl> - THDState : : s_workers = std : : vector < WorkerState > ( dataChannel - > getNumProcesses ( ) ) ; <nl> - <nl> - auto config = getInitConfig ( init_method , world_size , group_name , dataChannel - > getRank ( ) ) ; <nl> - masterCommandChannel . reset ( new MasterCommandChannel ( config ) ) ; <nl> - masterCommandChannel - > init ( ) ; <nl> - <nl> - END_HANDLE_EXCEPTIONS <nl> - } <nl> deleted file mode 100644 <nl> index 7c6088e5154e . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / Master . h <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include " . . / . . / THD . h " <nl> - # include < string > <nl> - <nl> - THD_API void THDMasterWorkerInit ( THDChannelType channel_type , std : : string init_method , <nl> - int world_size , std : : string group_name , int rank ) ; <nl> deleted file mode 100644 <nl> index 94f7e351dd9e . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / Master . hpp <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include " . . / common / CommandChannel . hpp " <nl> - # include " . . / . . / base / DataChannel . hpp " <nl> - <nl> - # include < memory > <nl> - <nl> - namespace thd { <nl> - namespace master { <nl> - <nl> - extern std : : unique_ptr < MasterCommandChannel > masterCommandChannel ; <nl> - <nl> - } / / namespace master <nl> - } / / namespace thd <nl> deleted file mode 100644 <nl> index c1c237f198c6 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / State . cpp <nl> ppp / dev / null <nl> <nl> - # include " State . hpp " <nl> - <nl> - # include < cstddef > <nl> - # include < cstdint > <nl> - <nl> - namespace thd { <nl> - namespace master { <nl> - <nl> - std : : vector < WorkerState > THDState : : s_workers ; <nl> - thread_local rank_type THDState : : s_current_worker = 1 ; <nl> - std : : uint64_t THDState : : s_nextId = 0 ; <nl> - <nl> - } / / namespace master <nl> - } / / namespace thd <nl> deleted file mode 100644 <nl> index b11199241ea6 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / State . h <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - THD_API int THDGetNode ( ) ; <nl> - THD_API int THDSetNode ( ) ; <nl> - THD_API int THDGetDevice ( ) ; <nl> - THD_API int THDSetDevice ( ) ; <nl> deleted file mode 100644 <nl> index 0dc1e9d23814 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / State . hpp <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include " . . / . . / base / DataChannel . h " <nl> - # include " . . / . . / base / ChannelUtils . hpp " <nl> - <nl> - # include < cstddef > <nl> - # include < cstdint > <nl> - # include < memory > <nl> - # include < mutex > <nl> - # include < vector > <nl> - <nl> - namespace thd { <nl> - namespace master { <nl> - <nl> - struct WorkerState { <nl> - WorkerState ( ) : copy_mutex ( ) { } <nl> - <nl> - std : : mutex copy_mutex ; <nl> - } ; <nl> - <nl> - struct THDState { <nl> - static std : : vector < WorkerState > s_workers ; <nl> - thread_local static rank_type s_current_worker ; <nl> - static std : : uint64_t s_nextId ; <nl> - } ; <nl> - <nl> - } / / namespace master <nl> - } / / namespace thd <nl> deleted file mode 100644 <nl> index c0ea72dadbe8 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / THDRandom . cpp <nl> ppp / dev / null <nl> <nl> - # include " THD . h " <nl> - # include " THDRandom . h " <nl> - <nl> - # include " Utils . hpp " <nl> - # include " State . hpp " <nl> - # include " master_worker / common / RPC . hpp " <nl> - # include " master_worker / common / Functions . hpp " <nl> - # include " master_worker / master / Master . hpp " <nl> - <nl> - # include < cstring > <nl> - <nl> - using namespace thd ; <nl> - using namespace rpc ; <nl> - using namespace master ; <nl> - <nl> - static THDGenerator * THDGenerator_newUnseeded ( ) { <nl> - THDGenerator * new_generator = new THDGenerator ( ) ; <nl> - new_generator - > generator_id = THDState : : s_nextId + + ; <nl> - return new_generator ; <nl> - } <nl> - <nl> - THDGenerator * THDGenerator_new ( ) { <nl> - THDGenerator * generator = THDGenerator_newUnseeded ( ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : generatorNew , generator ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - THDRandom_seed ( generator ) ; <nl> - return generator ; <nl> - } <nl> - <nl> - THDGenerator * THDGenerator_copy ( THDGenerator * self , THDGenerator * from ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : generatorCopy , self , from ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return self ; <nl> - } <nl> - <nl> - void THDGenerator_free ( THDGenerator * self ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : generatorFree , self ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - delete self ; <nl> - } <nl> - <nl> - uint64_t THDRandom_seed ( THDGenerator * _generator ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : generatorSeed , _generator ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < uint64_t > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - void THDRandom_manualSeed ( THDGenerator * _generator , uint64_t the_seed_ ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : generatorManualSeed , _generator , the_seed_ ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> deleted file mode 100644 <nl> index fea00812aaca . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / THDRandom . h <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include < TH / TH . h > <nl> - # include " . . / . . / THD . h " <nl> - <nl> - typedef struct THDGenerator { <nl> - / / Additional fields <nl> - uint64_t generator_id ; <nl> - } THDGenerator ; <nl> - <nl> - / * Manipulate THDGenerator objects * / <nl> - THD_API THDGenerator * THDGenerator_new ( void ) ; <nl> - THD_API THDGenerator * THDGenerator_copy ( THDGenerator * self , THDGenerator * from ) ; <nl> - THD_API void THDGenerator_free ( THDGenerator * gen ) ; <nl> - <nl> - / * Initializes the random number generator from / dev / urandom ( or on Windows <nl> - platforms with the current time ( granularity : seconds ) ) and returns the seed . * / <nl> - THD_API uint64_t THDRandom_seed ( THDGenerator * _generator ) ; <nl> - <nl> - / * Initializes the random number generator with the given uint64_t " the_seed_ " . * / <nl> - THD_API void THDRandom_manualSeed ( THDGenerator * _generator , uint64_t the_seed_ ) ; <nl> deleted file mode 100644 <nl> index 98286de93a5e . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / THDStorage . cpp <nl> ppp / dev / null <nl> <nl> - # include " THD . h " <nl> - # include " State . hpp " <nl> - # include " Utils . hpp " <nl> - # include " master_worker / common / RPC . hpp " <nl> - # include " master_worker / common / Functions . hpp " <nl> - # include " master_worker / master / Master . hpp " <nl> - # include " process_group / General . hpp " <nl> - <nl> - # include < cstring > <nl> - # include < memory > <nl> - <nl> - # include " master_worker / master / generic / THDStorage . cpp " <nl> - # include " TH / THGenerateAllTypes . h " <nl> - <nl> deleted file mode 100644 <nl> index e53fe46ad804 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / THDStorage . h <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include < TH / TH . h > <nl> - # include " . . / . . / THD . h " <nl> - <nl> - # define THDStorage TH_CONCAT_3 ( THD , Real , Storage ) <nl> - # define THDStorage_ ( NAME ) TH_CONCAT_4 ( THD , Real , Storage_ , NAME ) <nl> - <nl> - # include " generic / THDStorage . h " <nl> - # include < TH / THGenerateAllTypes . h > <nl> deleted file mode 100644 <nl> index 8ad2ca04e707 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / THDTensor . cpp <nl> ppp / dev / null <nl> <nl> - # define __STDC_FORMAT_MACROS <nl> - <nl> - # include " THDTensor . h " <nl> - # include " State . hpp " <nl> - # include " Utils . hpp " <nl> - # include " master_worker / common / RPC . hpp " <nl> - # include " master_worker / common / Functions . hpp " <nl> - # include " master_worker / master / Master . hpp " <nl> - # include " process_group / General . hpp " <nl> - <nl> - # include < cstring > <nl> - # include < memory > <nl> - # include < inttypes . h > <nl> - <nl> - # include " master_worker / master / generic / THDTensorMeta . cpp " <nl> - # include " TH / THGenerateAllTypes . h " <nl> - <nl> - # include " master_worker / master / generic / THDTensor . cpp " <nl> - # include " TH / THGenerateAllTypes . h " <nl> - <nl> - # include " master_worker / master / generic / THDTensorCopy . cpp " <nl> - # include " TH / THGenerateAllTypes . h " <nl> - <nl> - # include " master_worker / master / generic / THDTensorRandom . cpp " <nl> - # include " TH / THGenerateAllTypes . h " <nl> - <nl> - # include " master_worker / master / generic / THDTensorMath . cpp " <nl> - # include " TH / THGenerateAllTypes . h " <nl> - <nl> - # include " master_worker / master / generic / THDTensorLapack . cpp " <nl> - # include " TH / THGenerateFloatTypes . h " <nl> deleted file mode 100644 <nl> index e5aad7420c58 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / THDTensor . h <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include < TH / TH . h > <nl> - # include " . . / . . / THD . h " <nl> - <nl> - # define THDTensor TH_CONCAT_3 ( THD , Real , Tensor ) <nl> - # define THDTensor_ ( NAME ) TH_CONCAT_4 ( THD , Real , Tensor_ , NAME ) <nl> - <nl> - # define THD_DESC_BUFF_LEN 64 <nl> - typedef struct { <nl> - char str [ THD_DESC_BUFF_LEN ] ; <nl> - } THDDescBuff ; <nl> - <nl> - # include " generic / THDTensor . h " <nl> - # include < TH / THGenerateAllTypes . h > <nl> - <nl> - # include " generic / THDTensorCopy . h " <nl> - # include < TH / THGenerateAllTypes . h > <nl> - <nl> - # include " generic / THDTensorRandom . h " <nl> - # include < TH / THGenerateAllTypes . h > <nl> - <nl> - # include " generic / THDTensorMath . h " <nl> - # include < TH / THGenerateAllTypes . h > <nl> - <nl> - # include " generic / THDTensorLapack . h " <nl> - # include < TH / THGenerateFloatTypes . h > <nl> deleted file mode 100644 <nl> index 39431ad9b337 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / Utils . hpp <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include " process_group / General . hpp " <nl> - <nl> - template < typename T > <nl> - T receiveValueFromWorker ( int worker_id ) { <nl> - thd : : RPCType type = thd : : type_traits < T > : : type ; <nl> - if ( thd : : isInteger ( type ) ) { <nl> - thd : : IntScalar wrapped_value ; <nl> - thd : : dataChannel - > receive ( wrapped_value , worker_id ) ; <nl> - return static_cast < T > ( wrapped_value . value ( ) ) ; <nl> - } else if ( thd : : isFloat ( type ) ) { <nl> - thd : : FloatScalar wrapped_value ; <nl> - thd : : dataChannel - > receive ( wrapped_value , worker_id ) ; <nl> - return static_cast < T > ( wrapped_value . value ( ) ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> deleted file mode 100644 <nl> index 82c3b1bee6e6 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDStorage . cpp <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDStorage . cpp " <nl> - # else <nl> - <nl> - using namespace thd ; <nl> - using namespace rpc ; <nl> - using namespace master ; <nl> - <nl> - static THDStorage * THDStorage_ ( _alloc ) ( ) { <nl> - THDStorage * new_storage = new THDStorage ( ) ; <nl> - std : : memset ( reinterpret_cast < void * > ( new_storage ) , 0 , sizeof ( new_storage ) ) ; <nl> - new ( & new_storage - > refcount ) std : : atomic < int > ( 1 ) ; <nl> - new_storage - > storage_id = THDState : : s_nextId + + ; <nl> - new_storage - > node_id = THDState : : s_current_worker ; <nl> - new_storage - > flag = TH_STORAGE_REFCOUNTED | TH_STORAGE_RESIZABLE ; <nl> - return new_storage ; <nl> - } <nl> - <nl> - ptrdiff_t THDStorage_ ( size ) ( const THDStorage * storage ) { <nl> - return storage - > size ; <nl> - } <nl> - <nl> - size_t THDStorage_ ( elementSize ) ( void ) { <nl> - return sizeof ( real ) ; <nl> - } <nl> - <nl> - THDStorage * THDStorage_ ( new ) ( ) { <nl> - THDStorage * storage = THDStorage_ ( _alloc ) ( ) ; <nl> - RPCType type = type_traits < real > : : type ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageNew , <nl> - type , <nl> - storage <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return storage ; <nl> - } <nl> - <nl> - void THDStorage_ ( set ) ( THDStorage * storage , ptrdiff_t offset , real value ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageSet , <nl> - storage , <nl> - offset , <nl> - value <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - real THDStorage_ ( get ) ( const THDStorage * storage , ptrdiff_t offset ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageGet , <nl> - storage , <nl> - offset , <nl> - type_traits < real > : : type <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return receiveValueFromWorker < real > ( storage - > node_id ) ; <nl> - } <nl> - <nl> - THDStorage * THDStorage_ ( newWithSize ) ( ptrdiff_t size ) { <nl> - RPCType type = type_traits < real > : : type ; <nl> - THDStorage * storage = THDStorage_ ( _alloc ) ( ) ; <nl> - storage - > size = size ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageNewWithSize , <nl> - type , <nl> - storage , <nl> - size <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return storage ; <nl> - } <nl> - <nl> - THDStorage * THDStorage_ ( newWithSize1 ) ( real value ) { <nl> - RPCType type = type_traits < real > : : type ; <nl> - THDStorage * storage = THDStorage_ ( _alloc ) ( ) ; <nl> - storage - > size = 1 ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageNewWithSize1 , <nl> - type , <nl> - storage , <nl> - value <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return storage ; <nl> - } <nl> - <nl> - THDStorage * THDStorage_ ( newWithSize2 ) ( real value1 , real value2 ) { <nl> - RPCType type = type_traits < real > : : type ; <nl> - THDStorage * storage = THDStorage_ ( _alloc ) ( ) ; <nl> - storage - > size = 2 ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageNewWithSize1 , <nl> - type , <nl> - storage , <nl> - value1 , <nl> - value2 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return storage ; <nl> - } <nl> - <nl> - THDStorage * THDStorage_ ( newWithSize3 ) ( real value1 , real value2 , real value3 ) { <nl> - RPCType type = type_traits < real > : : type ; <nl> - THDStorage * storage = THDStorage_ ( _alloc ) ( ) ; <nl> - storage - > size = 3 ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageNewWithSize1 , <nl> - type , <nl> - storage , <nl> - value1 , <nl> - value2 , <nl> - value3 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return storage ; <nl> - } <nl> - <nl> - THDStorage * THDStorage_ ( newWithSize4 ) ( real value1 , real value2 , real value3 , real value4 ) { <nl> - RPCType type = type_traits < real > : : type ; <nl> - THDStorage * storage = THDStorage_ ( _alloc ) ( ) ; <nl> - storage - > size = 4 ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageNewWithSize1 , <nl> - type , <nl> - storage , <nl> - value1 , <nl> - value2 , <nl> - value3 , <nl> - value4 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return storage ; <nl> - } <nl> - <nl> - void THDStorage_ ( setFlag ) ( THDStorage * storage , const char flag ) { <nl> - storage - > flag | = flag ; <nl> - } <nl> - <nl> - void THDStorage_ ( clearFlag ) ( THDStorage * storage , const char flag ) { <nl> - storage - > flag & = ~ flag ; <nl> - } <nl> - <nl> - void THDStorage_ ( retain ) ( THDStorage * storage ) { <nl> - if ( storage & & ( storage - > flag & TH_STORAGE_REFCOUNTED ) ) <nl> - storage - > refcount + + ; <nl> - } <nl> - <nl> - void THDStorage_ ( swap ) ( THDStorage * storage1 , THDStorage * storage2 ) { <nl> - THDStorage dummy = * storage1 ; <nl> - * storage1 = * storage2 ; <nl> - * storage2 = dummy ; <nl> - } <nl> - <nl> - void THDStorage_ ( free ) ( THDStorage * storage ) { <nl> - if ( ! storage | | ! ( storage - > flag & TH_STORAGE_REFCOUNTED ) ) return ; <nl> - <nl> - if ( - - storage - > refcount = = 0 ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageFree , <nl> - storage <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - delete storage ; <nl> - } <nl> - } <nl> - <nl> - void THDStorage_ ( resize ) ( THDStorage * storage , ptrdiff_t size ) { <nl> - if ( ! ( storage - > flag & TH_STORAGE_RESIZABLE ) ) <nl> - THError ( " Trying to resize storage that is not resizable " ) ; <nl> - if ( size < storage - > size ) <nl> - return ; <nl> - <nl> - storage - > size = size ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageResize , <nl> - storage , <nl> - size <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDStorage_ ( fill ) ( THDStorage * storage , real value ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : storageFill , <nl> - storage , <nl> - value <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - # endif <nl> deleted file mode 100644 <nl> index 4d99332980d8 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDStorage . h <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDStorage . h " <nl> - # else <nl> - <nl> - typedef struct THDStorage { <nl> - uint64_t storage_id ; <nl> - ptrdiff_t size ; <nl> - int refcount ; <nl> - char flag ; <nl> - / / these are here only so that the struct has a similar structure to TH <nl> - void * allocator ; <nl> - void * allocatorContext ; <nl> - struct THDStorage * view ; <nl> - / / Additional fields <nl> - int node_id ; <nl> - int device_id ; / / unused at the moment <nl> - } THDStorage ; <nl> - <nl> - THD_API ptrdiff_t THDStorage_ ( size ) ( const THDStorage * ) ; <nl> - THD_API size_t THDStorage_ ( elementSize ) ( void ) ; <nl> - <nl> - / * slow access - - checks everything * / <nl> - THD_API void THDStorage_ ( set ) ( THDStorage * , ptrdiff_t , real ) ; <nl> - THD_API real THDStorage_ ( get ) ( const THDStorage * , ptrdiff_t ) ; <nl> - <nl> - THD_API THDStorage * THDStorage_ ( new ) ( void ) ; <nl> - THD_API THDStorage * THDStorage_ ( newWithSize ) ( ptrdiff_t size ) ; <nl> - THD_API THDStorage * THDStorage_ ( newWithSize1 ) ( real ) ; <nl> - THD_API THDStorage * THDStorage_ ( newWithSize2 ) ( real , real ) ; <nl> - THD_API THDStorage * THDStorage_ ( newWithSize3 ) ( real , real , real ) ; <nl> - THD_API THDStorage * THDStorage_ ( newWithSize4 ) ( real , real , real , real ) ; <nl> - THD_API THDStorage * THDStorage_ ( newWithMapping ) ( const char * filename , ptrdiff_t size , int flags ) ; <nl> - <nl> - / * takes ownership of data * / <nl> - / / THD_API THDStorage * THDStorage_ ( newWithAllocator ) ( ptrdiff_t size , <nl> - / / THDAllocator * allocator , <nl> - / / void * allocatorContext ) ; <nl> - / / THD_API THDStorage * THDStorage_ ( newWithDataAndAllocator ) ( <nl> - / / real * data , ptrdiff_t size , THDAllocator * allocator , void * allocatorContext ) ; <nl> - <nl> - / * should not differ with API * / <nl> - THD_API void THDStorage_ ( setFlag ) ( THDStorage * storage , const char flag ) ; <nl> - THD_API void THDStorage_ ( clearFlag ) ( THDStorage * storage , const char flag ) ; <nl> - THD_API void THDStorage_ ( retain ) ( THDStorage * storage ) ; <nl> - THD_API void THDStorage_ ( swap ) ( THDStorage * storage1 , THDStorage * storage2 ) ; <nl> - <nl> - / * might differ with other API ( like CUDA ) * / <nl> - THD_API void THDStorage_ ( free ) ( THDStorage * storage ) ; <nl> - THD_API void THDStorage_ ( resize ) ( THDStorage * storage , ptrdiff_t size ) ; <nl> - THD_API void THDStorage_ ( fill ) ( THDStorage * storage , real value ) ; <nl> - <nl> - # endif <nl> - <nl> deleted file mode 100644 <nl> index a465236fdbe4 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensor . cpp <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensor . cpp " <nl> - # else <nl> - <nl> - using namespace thd ; <nl> - using namespace rpc ; <nl> - using namespace master ; <nl> - <nl> - / / taken from TH ( generic / THTensor . c ) <nl> - THDDescBuff THDTensor_ ( sizeDesc ) ( const THDTensor * tensor ) { <nl> - const int L = THD_DESC_BUFF_LEN ; <nl> - THDDescBuff buf ; <nl> - char * str = buf . str ; <nl> - int n = 0 ; <nl> - n + = snprintf ( str , L - n , " [ " ) ; <nl> - int i ; <nl> - for ( i = 0 ; i < tensor - > nDimension ; i + + ) { <nl> - if ( n > = L ) break ; <nl> - n + = snprintf ( str + n , L - n , " % " PRId64 , tensor - > size [ i ] ) ; <nl> - if ( i < tensor - > nDimension - 1 ) { <nl> - n + = snprintf ( str + n , L - n , " x " ) ; <nl> - } <nl> - } <nl> - if ( n < L - 2 ) { <nl> - snprintf ( str + n , L - n , " ] " ) ; <nl> - } else { <nl> - snprintf ( str + L - 5 , 5 , " . . . ] " ) ; <nl> - } <nl> - return buf ; <nl> - } <nl> - <nl> - THDStorage * THDTensor_ ( storage ) ( const THDTensor * self ) { <nl> - return self - > storage ; <nl> - } <nl> - <nl> - ptrdiff_t THDTensor_ ( storageOffset ) ( const THDTensor * self ) { <nl> - return self - > storageOffset ; <nl> - } <nl> - <nl> - int THDTensor_ ( nDimensionLegacyNoScalars ) ( const THDTensor * self ) { <nl> - return self - > nDimension ; <nl> - } <nl> - <nl> - int64_t THDTensor_ ( size ) ( const THDTensor * self , int dim ) { <nl> - THArgCheck ( ( dim > = 0 ) & & ( dim < self - > nDimension ) , 2 , " dimension % d out of range of % dD tensor " , <nl> - dim + 1 , THDTensor_ ( nDimensionLegacyNoScalars ) ( self ) ) ; <nl> - return self - > size [ dim ] ; <nl> - } <nl> - <nl> - int64_t THDTensor_ ( stride ) ( const THDTensor * self , int dim ) { <nl> - THArgCheck ( ( dim > = 0 ) & & ( dim < self - > nDimension ) , 2 , " dimension % d out of range of % dD tensor " , dim + 1 , <nl> - THDTensor_ ( nDimensionLegacyNoScalars ) ( self ) ) ; <nl> - return self - > stride [ dim ] ; <nl> - } <nl> - <nl> - THLongStorage * THDTensor_ ( newSizeOf ) ( THDTensor * self ) { <nl> - THLongStorage * size = THLongStorage_newWithSize ( self - > nDimension ) ; <nl> - THLongStorage_rawCopy ( size , self - > size ) ; <nl> - return size ; <nl> - } <nl> - <nl> - THLongStorage * THDTensor_ ( newStrideOf ) ( THDTensor * self ) { <nl> - THLongStorage * stride = THLongStorage_newWithSize ( self - > nDimension ) ; <nl> - THLongStorage_rawCopy ( stride , self - > stride ) ; <nl> - return stride ; <nl> - } <nl> - <nl> - void THDTensor_ ( setFlag ) ( THDTensor * self , char flag ) { <nl> - self - > flag | = flag ; <nl> - } <nl> - <nl> - void THDTensor_ ( clearFlag ) ( THDTensor * self , char flag ) { <nl> - self - > flag & = ~ flag ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( new ) ( ) { <nl> - THDTensor * tensor = THDTensor_ ( _alloc ) ( ) ; <nl> - RPCType constructed_type = type_traits < real > : : type ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorNew , <nl> - constructed_type , <nl> - tensor <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return tensor ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newWithTensor ) ( THDTensor * self ) { <nl> - THDTensor * tensor = THDTensor_ ( _alloc ) ( ) ; <nl> - THDTensor_ ( _set ) ( <nl> - tensor , <nl> - self - > storage , <nl> - self - > storageOffset , <nl> - self - > nDimension , <nl> - self - > size , <nl> - self - > stride <nl> - ) ; <nl> - RPCType constructed_type = type_traits < real > : : type ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorNewWithTensor , <nl> - constructed_type , <nl> - tensor , <nl> - self <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return tensor ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newWithSize ) ( THLongStorage * size , THLongStorage * stride ) { <nl> - THDTensor * tensor = THDTensor_ ( _alloc ) ( ) ; <nl> - if ( size & & stride ) <nl> - THArgCheck ( THLongStorage_size ( size ) = = THLongStorage_size ( stride ) , 4 , " inconsistent size " ) ; <nl> - THDTensor_ ( _resize ) ( tensor , THLongStorage_size ( size ) , THLongStorage_data ( size ) , stride ? THLongStorage_data ( stride ) : nullptr ) ; <nl> - RPCType constructed_type = type_traits < real > : : type ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorNewWithSize , <nl> - constructed_type , <nl> - tensor , <nl> - size , <nl> - stride <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return tensor ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newWithSize1d ) ( int64_t size0 ) { <nl> - THLongStorage * size = THLongStorage_newWithSize1 ( size0 ) ; <nl> - THDTensor * tensor = THDTensor_ ( newWithSize ) ( size , NULL ) ; <nl> - THLongStorage_free ( size ) ; <nl> - return tensor ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newWithSize2d ) ( int64_t size0 , int64_t size1 ) { <nl> - THLongStorage * size = THLongStorage_newWithSize2 ( size0 , size1 ) ; <nl> - THDTensor * tensor = THDTensor_ ( newWithSize ) ( size , NULL ) ; <nl> - THLongStorage_free ( size ) ; <nl> - return tensor ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newWithSize3d ) ( int64_t size0 , int64_t size1 , int64_t size2 ) { <nl> - THLongStorage * size = THLongStorage_newWithSize3 ( size0 , size1 , size2 ) ; <nl> - THDTensor * tensor = THDTensor_ ( newWithSize ) ( size , NULL ) ; <nl> - THLongStorage_free ( size ) ; <nl> - return tensor ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newWithSize4d ) ( int64_t size0 , int64_t size1 , int64_t size2 , int64_t size3 ) { <nl> - THLongStorage * size = THLongStorage_newWithSize4 ( size0 , size1 , size2 , size3 ) ; <nl> - THDTensor * tensor = THDTensor_ ( newWithSize ) ( size , NULL ) ; <nl> - THLongStorage_free ( size ) ; <nl> - return tensor ; <nl> - } <nl> - <nl> - <nl> - THDTensor * THDTensor_ ( newWithStorage ) ( THDStorage * storage , ptrdiff_t storageOffset , <nl> - THLongStorage * size , THLongStorage * stride ) { <nl> - THDTensor * tensor = THDTensor_ ( _alloc ) ( ) ; <nl> - THDTensor_ ( _set ) ( <nl> - tensor , <nl> - storage , <nl> - storageOffset , <nl> - ( size ? THLongStorage_size ( size ) : ( stride ? THLongStorage_size ( stride ) : 0 ) ) , <nl> - ( size ? THLongStorage_data ( size ) : nullptr ) , <nl> - ( stride ? THLongStorage_data ( stride ) : nullptr ) <nl> - ) ; <nl> - RPCType constructed_type = type_traits < real > : : type ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorNewWithStorage , <nl> - constructed_type , <nl> - storage , <nl> - storageOffset , <nl> - size , <nl> - stride <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return tensor ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newWithStorage1d ) ( THDStorage * storage , ptrdiff_t storageOffset , <nl> - int64_t size0 , int64_t stride0 ) { <nl> - THLongStorage * size = THLongStorage_newWithSize1 ( size0 ) ; <nl> - THLongStorage * stride = THLongStorage_newWithSize1 ( stride0 ) ; <nl> - THDTensor * tensor = THDTensor_ ( newWithStorage ) ( storage , storageOffset , size , stride ) ; <nl> - THLongStorage_free ( size ) ; <nl> - THLongStorage_free ( stride ) ; <nl> - return tensor ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newWithStorage2d ) ( THDStorage * storage , ptrdiff_t storageOffset , <nl> - int64_t size0 , int64_t stride0 , int64_t size1 , int64_t stride1 ) { <nl> - THLongStorage * size = THLongStorage_newWithSize2 ( size0 , size1 ) ; <nl> - THLongStorage * stride = THLongStorage_newWithSize2 ( stride0 , stride1 ) ; <nl> - THDTensor * tensor = THDTensor_ ( newWithStorage ) ( storage , storageOffset , size , stride ) ; <nl> - THLongStorage_free ( size ) ; <nl> - THLongStorage_free ( stride ) ; <nl> - return tensor ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newWithStorage3d ) ( THDStorage * storage , ptrdiff_t storageOffset , <nl> - int64_t size0 , int64_t stride0 , int64_t size1 , int64_t stride1 , <nl> - int64_t size2 , int64_t stride2 ) { <nl> - THLongStorage * size = THLongStorage_newWithSize3 ( size0 , size1 , size2 ) ; <nl> - THLongStorage * stride = THLongStorage_newWithSize3 ( stride0 , stride1 , stride2 ) ; <nl> - THDTensor * tensor = THDTensor_ ( newWithStorage ) ( storage , storageOffset , size , stride ) ; <nl> - THLongStorage_free ( size ) ; <nl> - THLongStorage_free ( stride ) ; <nl> - return THDTensor_ ( newWithStorage ) ( storage , storageOffset , size , stride ) ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newWithStorage4d ) ( THDStorage * storage , ptrdiff_t storageOffset , <nl> - int64_t size0 , int64_t stride0 , int64_t size1 , int64_t stride1 , <nl> - int64_t size2 , int64_t stride2 , int64_t size3 , int64_t stride3 ) { <nl> - THLongStorage * size = THLongStorage_newWithSize4 ( size0 , size1 , size2 , size3 ) ; <nl> - THLongStorage * stride = THLongStorage_newWithSize4 ( stride0 , stride1 , stride2 , stride3 ) ; <nl> - THDTensor * tensor = THDTensor_ ( newWithStorage ) ( storage , storageOffset , size , stride ) ; <nl> - THLongStorage_free ( size ) ; <nl> - THLongStorage_free ( stride ) ; <nl> - return THDTensor_ ( newWithStorage ) ( storage , storageOffset , size , stride ) ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newClone ) ( THDTensor * self ) { <nl> - THDTensor * clone = THDTensor_ ( _alloc ) ( ) ; <nl> - THDTensor_ ( _resize ) ( clone , self - > nDimension , self - > size , self - > stride ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorNewClone , <nl> - clone , <nl> - self <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return clone ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newContiguous ) ( THDTensor * self ) { <nl> - if ( ! THDTensor_ ( isContiguous ) ( self ) ) { <nl> - return THDTensor_ ( newClone ) ( self ) ; <nl> - } else { <nl> - THDTensor_ ( retain ) ( self ) ; <nl> - return self ; <nl> - } <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newSelect ) ( THDTensor * tensor , int dimension , int64_t sliceIndex ) { <nl> - THDTensor * self = THDTensor_ ( newWithTensor ) ( tensor ) ; <nl> - THDTensor_ ( select ) ( self , NULL , dimension , sliceIndex ) ; <nl> - return self ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newNarrow ) ( THDTensor * tensor , int dimension , <nl> - int64_t firstIndex , int64_t size ) { <nl> - THDTensor * self = THDTensor_ ( newWithTensor ) ( tensor ) ; <nl> - THDTensor_ ( narrow ) ( self , NULL , dimension , firstIndex , size ) ; <nl> - return self ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newTranspose ) ( THDTensor * tensor , int dimension1 , int dimension2 ) { <nl> - THDTensor * self = THDTensor_ ( newWithTensor ) ( tensor ) ; <nl> - THDTensor_ ( transpose ) ( self , NULL , dimension1 , dimension2 ) ; <nl> - return self ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newUnfold ) ( THDTensor * tensor , int dimension , int64_t size , int64_t step ) { <nl> - THDTensor * self = THDTensor_ ( newWithTensor ) ( tensor ) ; <nl> - THDTensor_ ( unfold ) ( self , NULL , dimension , size , step ) ; <nl> - return self ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newView ) ( THDTensor * tensor , THLongStorage * size ) { <nl> - / / TODO <nl> - THError ( " newView not implemented " ) ; <nl> - return nullptr ; <nl> - } <nl> - <nl> - THDTensor * THDTensor_ ( newExpand ) ( THDTensor * tensor , THLongStorage * size ) { <nl> - / / TODO <nl> - THError ( " newExpand not implemented " ) ; <nl> - return nullptr ; <nl> - } <nl> - <nl> - void THDTensor_ ( resize ) ( THDTensor * tensor , THLongStorage * size , THLongStorage * stride ) { <nl> - THArgCheck ( size ! = NULL , 2 , " invalid size " ) ; <nl> - if ( stride ) <nl> - THArgCheck ( THLongStorage_size ( stride ) = = THLongStorage_size ( size ) , 3 , " invalid stride " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorResize , <nl> - tensor , <nl> - size , <nl> - stride <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - THDTensor_ ( _resize ) ( tensor , THLongStorage_size ( size ) , THLongStorage_data ( size ) , stride ? THLongStorage_data ( stride ) : nullptr ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( resizeAs ) ( THDTensor * tensor , THDTensor * src ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorResizeAs , <nl> - tensor , <nl> - src <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - THDTensor_ ( _resize ) ( tensor , src - > nDimension , src - > size , nullptr ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( resize1d ) ( THDTensor * tensor , int64_t size0 ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorResize1d , <nl> - tensor , <nl> - size0 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - THDTensor_ ( _resize ) ( tensor , 1 , & size0 , nullptr ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( resize2d ) ( THDTensor * tensor , int64_t size0 , int64_t size1 ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorResize2d , <nl> - tensor , <nl> - size0 , <nl> - size1 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - THDTensor_ ( _resize2d ) ( tensor , size0 , size1 ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( resize3d ) ( THDTensor * tensor , int64_t size0 , int64_t size1 , int64_t size2 ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorResize3d , <nl> - tensor , <nl> - size0 , <nl> - size1 , <nl> - size2 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - THDTensor_ ( _resize3d ) ( tensor , size0 , size1 , size2 ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( resize4d ) ( THDTensor * tensor , int64_t size0 , int64_t size1 , int64_t size2 , int64_t size3 ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorResize4d , <nl> - tensor , <nl> - size0 , <nl> - size1 , <nl> - size2 , <nl> - size3 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - THDTensor_ ( _resize4d ) ( tensor , size0 , size1 , size2 , size3 ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( resize5d ) ( THDTensor * tensor , int64_t size0 , int64_t size1 , int64_t size2 , int64_t size3 , int64_t size4 ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorResize5d , <nl> - tensor , <nl> - size0 , <nl> - size1 , <nl> - size2 , <nl> - size3 , <nl> - size4 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - THDTensor_ ( _resize5d ) ( tensor , size0 , size1 , size2 , size3 , size4 ) ; <nl> - } <nl> - <nl> - real THDTensor_ ( get1d ) ( const THDTensor * tensor , int64_t x0 ) <nl> - { <nl> - / / TODO <nl> - THError ( " get1d not supported ! " ) ; <nl> - / / THArgCheck ( tensor - > nDimension = = 1 , 1 , " tensor must have one dimension " ) ; <nl> - / / THArgCheck ( ( x0 > = 0 ) & & ( x0 < tensor - > size [ 0 ] ) , 2 , " out of range " ) ; <nl> - / / return THDStorage_ ( get ) ( tensor - > storage , tensor - > storageOffset + x0 * tensor - > stride [ 0 ] ) ; <nl> - return 0 ; <nl> - } <nl> - <nl> - void THDTensor_ ( set ) ( THDTensor * self , THDTensor * src ) { <nl> - if ( self = = src ) <nl> - return ; <nl> - <nl> - THDTensor_ ( _set ) ( self , src - > storage , src - > storageOffset , <nl> - src - > nDimension , src - > size , src - > stride ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorSet , <nl> - self , <nl> - src <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( setStorage ) ( THDTensor * self , THDStorage * storage , <nl> - ptrdiff_t storageOffset , THLongStorage * size , <nl> - THLongStorage * stride ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorSetStorage , <nl> - self , <nl> - storage , <nl> - storageOffset , <nl> - size , <nl> - stride <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - if ( size & & stride ) <nl> - THArgCheck ( THLongStorage_size ( size ) = = THLongStorage_size ( stride ) , 5 , " inconsistent number of sizes and strides " ) ; <nl> - <nl> - THDTensor_ ( _set ) ( <nl> - self , <nl> - storage , <nl> - storageOffset , <nl> - ( size ? THLongStorage_size ( size ) : ( stride ? THLongStorage_size ( stride ) : 0 ) ) , <nl> - ( size ? THLongStorage_data ( size ) : nullptr ) , <nl> - ( stride ? THLongStorage_data ( stride ) : nullptr ) <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( setStorage1d ) ( THDTensor * self , <nl> - THDStorage * storage , <nl> - ptrdiff_t storageOffset , <nl> - int64_t size0 , int64_t stride0 ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorSetStorage1d , <nl> - self , <nl> - storage , <nl> - storageOffset , <nl> - size0 , <nl> - stride0 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - int64_t size [ ] = { size0 } ; <nl> - int64_t stride [ ] = { stride0 } ; <nl> - THDTensor_ ( _set ) ( <nl> - self , <nl> - storage , <nl> - storageOffset , <nl> - 1 , <nl> - size , <nl> - stride <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( setStorage2d ) ( THDTensor * self , <nl> - THDStorage * storage , <nl> - ptrdiff_t storageOffset , <nl> - int64_t size0 , int64_t stride0 , <nl> - int64_t size1 , int64_t stride1 ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorSetStorage2d , <nl> - self , <nl> - storage , <nl> - storageOffset , <nl> - size0 , <nl> - size1 , <nl> - stride0 , <nl> - stride1 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - int64_t size [ ] = { size0 , size1 } ; <nl> - int64_t stride [ ] = { stride0 , stride1 } ; <nl> - THDTensor_ ( _set ) ( <nl> - self , <nl> - storage , <nl> - storageOffset , <nl> - 2 , <nl> - size , <nl> - stride <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( setStorage3d ) ( THDTensor * self , <nl> - THDStorage * storage , <nl> - ptrdiff_t storageOffset , <nl> - int64_t size0 , int64_t stride0 , <nl> - int64_t size1 , int64_t stride1 , <nl> - int64_t size2 , int64_t stride2 ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorSetStorage2d , <nl> - self , <nl> - storage , <nl> - storageOffset , <nl> - size0 , <nl> - size1 , <nl> - size2 , <nl> - stride0 , <nl> - stride1 , <nl> - stride2 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - int64_t size [ ] = { size0 , size1 , size2 } ; <nl> - int64_t stride [ ] = { stride0 , stride1 , stride2 } ; <nl> - THDTensor_ ( _set ) ( <nl> - self , <nl> - storage , <nl> - storageOffset , <nl> - 3 , <nl> - size , <nl> - stride <nl> - ) ; <nl> - } <nl> - void THDTensor_ ( setStorage4d ) ( THDTensor * self , <nl> - THDStorage * storage , <nl> - ptrdiff_t storageOffset , <nl> - int64_t size0 , int64_t stride0 , <nl> - int64_t size1 , int64_t stride1 , <nl> - int64_t size2 , int64_t stride2 , <nl> - int64_t size3 , int64_t stride3 ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorSetStorage2d , <nl> - self , <nl> - storage , <nl> - storageOffset , <nl> - size0 , <nl> - size1 , <nl> - size2 , <nl> - size3 , <nl> - stride0 , <nl> - stride1 , <nl> - stride2 , <nl> - stride3 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - int64_t size [ ] = { size0 , size1 , size2 , size3 } ; <nl> - int64_t stride [ ] = { stride0 , stride1 , stride2 , stride3 } ; <nl> - THDTensor_ ( _set ) ( <nl> - self , <nl> - storage , <nl> - storageOffset , <nl> - 4 , <nl> - size , <nl> - stride <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( narrow ) ( THDTensor * self , THDTensor * src , int dimension , <nl> - int64_t firstIndex , int64_t size ) { <nl> - if ( ! src ) src = self ; <nl> - <nl> - THArgCheck ( ( dimension > = 0 ) & & ( dimension < src - > nDimension ) , 2 , " out of range " ) ; <nl> - THArgCheck ( ( firstIndex > = 0 ) & & ( firstIndex < src - > size [ dimension ] ) , 3 , " out of range " ) ; <nl> - THArgCheck ( ( size > 0 ) & & ( firstIndex < = src - > size [ dimension ] - size ) , 4 , " out of range " ) ; <nl> - <nl> - THDTensor_ ( set ) ( self , src ) ; <nl> - <nl> - if ( firstIndex > 0 ) <nl> - self - > storageOffset + = firstIndex * self - > stride [ dimension ] ; <nl> - <nl> - self - > size [ dimension ] = size ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorNarrow , <nl> - self , <nl> - src , <nl> - dimension , <nl> - firstIndex , <nl> - size <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( select ) ( THDTensor * self , THDTensor * src , int dimension , int64_t sliceIndex ) { <nl> - if ( ! src ) <nl> - src = self ; <nl> - <nl> - THArgCheck ( src - > nDimension > 1 , 1 , " cannot select on a vector " ) ; <nl> - THArgCheck ( ( dimension > = 0 ) & & ( dimension < src - > nDimension ) , 2 , " out of range " ) ; <nl> - THArgCheck ( ( sliceIndex > = 0 ) & & ( sliceIndex < src - > size [ dimension ] ) , 3 , " out of range " ) ; <nl> - <nl> - THDTensor_ ( set ) ( self , src ) ; <nl> - THDTensor_ ( narrow ) ( self , NULL , dimension , sliceIndex , 1 ) ; <nl> - for ( int d = dimension ; d < self - > nDimension - 1 ; d + + ) { <nl> - self - > size [ d ] = self - > size [ d + 1 ] ; <nl> - self - > stride [ d ] = self - > stride [ d + 1 ] ; <nl> - } <nl> - self - > nDimension - - ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorSelect , <nl> - self , <nl> - src , <nl> - dimension , <nl> - sliceIndex <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( transpose ) ( THDTensor * self , THDTensor * src , int dimension1 , <nl> - int dimension2 ) { <nl> - if ( ! src ) <nl> - src = self ; <nl> - <nl> - THArgCheck ( ( dimension1 > = 0 ) & & dimension1 < src - > nDimension , 1 , <nl> - " out of range " ) ; <nl> - THArgCheck ( ( dimension2 > = 0 ) & & dimension2 < src - > nDimension , 1 , <nl> - " out of range " ) ; <nl> - <nl> - THDTensor_ ( set ) ( self , src ) ; <nl> - <nl> - if ( dimension1 = = dimension2 ) <nl> - return ; <nl> - <nl> - std : : swap ( self - > stride [ dimension1 ] , self - > stride [ dimension2 ] ) ; <nl> - std : : swap ( self - > size [ dimension1 ] , self - > size [ dimension2 ] ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorTranspose , <nl> - self , <nl> - src , <nl> - dimension1 , <nl> - dimension2 <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( unfold ) ( THDTensor * self , THDTensor * src , <nl> - int dimension , int64_t size , int64_t step ) { <nl> - int64_t * newSize , * newStride ; <nl> - if ( ! src ) <nl> - src = self ; <nl> - <nl> - THArgCheck ( ( src - > nDimension > 0 ) , 1 , " cannot unfold an empty tensor " ) ; <nl> - THArgCheck ( ( dimension > 0 ) & & ( dimension < src - > nDimension ) , 2 , <nl> - " out of range " ) ; <nl> - THArgCheck ( size < = src - > size [ dimension ] , 3 , " out of range " ) ; <nl> - THArgCheck ( step > 0 , 4 , " invalid step " ) ; <nl> - <nl> - THDTensor_ ( set ) ( self , src ) ; <nl> - <nl> - newSize = new int64_t [ self - > nDimension + 1 ] ; <nl> - newStride = new int64_t [ self - > nDimension + 1 ] ; <nl> - <nl> - newSize [ self - > nDimension ] = size ; <nl> - newStride [ self - > nDimension ] = self - > stride [ dimension ] ; <nl> - <nl> - for ( size_t d = 0 ; d < self - > nDimension ; d + + ) { <nl> - if ( d = = dimension ) { <nl> - newSize [ d ] = ( self - > size [ d ] - size ) / step + 1 ; <nl> - newStride [ d ] = step * self - > stride [ d ] ; <nl> - } else { <nl> - newSize [ d ] = self - > size [ d ] ; <nl> - newStride [ d ] = self - > stride [ d ] ; <nl> - } <nl> - } <nl> - <nl> - <nl> - delete [ ] self - > size ; <nl> - delete [ ] self - > stride ; <nl> - <nl> - self - > size = newSize ; <nl> - self - > stride = newStride ; <nl> - self - > nDimension + + ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorUnfold , <nl> - self , <nl> - src , <nl> - dimension , <nl> - size , <nl> - step <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( squeeze ) ( THDTensor * self , THDTensor * src ) { <nl> - int ndim = 0 ; <nl> - <nl> - if ( ! src ) <nl> - src = self ; <nl> - <nl> - THDTensor_ ( set ) ( self , src ) ; <nl> - <nl> - for ( size_t d = 0 ; d < src - > nDimension ; d + + ) { <nl> - if ( src - > size [ d ] ! = 1 ) { <nl> - if ( d ! = ndim ) { <nl> - self - > size [ ndim ] = src - > size [ d ] ; <nl> - self - > stride [ ndim ] = src - > stride [ d ] ; <nl> - } <nl> - ndim + + ; <nl> - } <nl> - } <nl> - <nl> - / * right now , we do not handle 0 - dimension tensors * / <nl> - if ( ndim = = 0 & & src - > nDimension > 0 ) { <nl> - self - > size [ 0 ] = 1 ; <nl> - self - > stride [ 0 ] = 1 ; <nl> - ndim = 1 ; <nl> - } <nl> - self - > nDimension = ndim ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorSqueeze , self , src ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( squeeze1d ) ( THDTensor * self , THDTensor * src , int dimension ) { <nl> - THDTensor_ ( _squeeze1d ) ( self , src , dimension ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorSqueeze1d , self , src ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( unsqueeze1d ) ( THDTensor * self , THDTensor * src , int dimension ) <nl> - { <nl> - int d ; <nl> - <nl> - if ( ! src ) <nl> - src = self ; <nl> - <nl> - THArgCheck ( ( dimension > = 0 ) & & ( dimension < = src - > nDimension ) , 3 , " dimension out of range " ) ; <nl> - THArgCheck ( src - > nDimension > 0 , 3 , " cannot unsqueeze empty tensor " ) ; <nl> - <nl> - THDTensor_ ( set ) ( self , src ) ; <nl> - <nl> - self - > size = ( int64_t * ) THRealloc ( self - > size , sizeof ( int64_t ) * ( self - > nDimension + 1 ) ) ; <nl> - self - > stride = ( int64_t * ) THRealloc ( self - > stride , sizeof ( int64_t ) * ( self - > nDimension + 1 ) ) ; <nl> - self - > nDimension + + ; <nl> - for ( d = self - > nDimension - 1 ; d > dimension ; d - - ) { <nl> - self - > size [ d ] = self - > size [ d - 1 ] ; <nl> - self - > stride [ d ] = self - > stride [ d - 1 ] ; <nl> - } <nl> - if ( dimension + 1 < self - > nDimension ) { <nl> - self - > stride [ dimension ] = self - > size [ dimension + 1 ] * self - > stride [ dimension + 1 ] ; <nl> - } else { <nl> - self - > stride [ dimension ] = 1 ; <nl> - } <nl> - self - > size [ dimension ] = 1 ; <nl> - } <nl> - <nl> - int THDTensor_ ( isContiguous ) ( const THDTensor * self ) { <nl> - int64_t z = 1 ; <nl> - for ( std : : ptrdiff_t d = self - > nDimension - 1 ; d > = 0 ; d - - ) { <nl> - if ( self - > size [ d ] ! = 1 ) { <nl> - if ( self - > stride [ d ] = = z ) <nl> - z * = self - > size [ d ] ; <nl> - else <nl> - return 0 ; <nl> - } <nl> - } <nl> - return 1 ; <nl> - } <nl> - <nl> - int THDTensor_ ( isSameSizeAs ) ( const THDTensor * self , const THDTensor * src ) { <nl> - if ( self - > nDimension ! = src - > nDimension ) <nl> - return 0 ; <nl> - for ( size_t d = 0 ; d < self - > nDimension ; d + + ) <nl> - if ( self - > size [ d ] ! = src - > size [ d ] ) <nl> - return 0 ; <nl> - return 1 ; <nl> - } <nl> - <nl> - int THDTensor_ ( isSetTo ) ( const THDTensor * self , const THDTensor * src ) { <nl> - if ( ! self - > storage ) <nl> - return 0 ; <nl> - if ( self - > storage = = src - > storage & & <nl> - self - > storageOffset = = src - > storageOffset & & <nl> - self - > nDimension = = src - > nDimension ) { <nl> - for ( size_t d = 0 ; d < self - > nDimension ; d + + ) { <nl> - if ( self - > size [ d ] ! = src - > size [ d ] | | self - > stride [ d ] ! = src - > stride [ d ] ) <nl> - return 0 ; <nl> - } <nl> - return 1 ; <nl> - } <nl> - return 0 ; <nl> - } <nl> - <nl> - int THDTensor_ ( isSize ) ( const THDTensor * self , const THLongStorage * dims ) { <nl> - if ( self - > nDimension ! = THLongStorage_size ( dims ) ) <nl> - return 0 ; <nl> - for ( size_t d = 0 ; d < self - > nDimension ; d + + ) <nl> - if ( self - > size [ d ] ! = THLongStorage_get ( dims , d ) ) <nl> - return 0 ; <nl> - return 1 ; <nl> - } <nl> - <nl> - ptrdiff_t THDTensor_ ( nElement ) ( const THDTensor * self ) { <nl> - if ( self - > nDimension = = 0 ) { <nl> - return 0 ; <nl> - } else { <nl> - ptrdiff_t nElement = 1 ; <nl> - for ( size_t d = 0 ; d < self - > nDimension ; d + + ) { <nl> - nElement * = self - > size [ d ] ; <nl> - } <nl> - return nElement ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( retain ) ( THDTensor * tensor ) { <nl> - tensor - > refcount + + ; <nl> - } <nl> - <nl> - void THDTensor_ ( free ) ( THDTensor * tensor ) { <nl> - if ( ! tensor ) <nl> - return ; <nl> - <nl> - / / TODO : check refcounted flag ? <nl> - if ( - - tensor - > refcount = = 0 ) { <nl> - delete [ ] tensor - > size ; <nl> - delete [ ] tensor - > stride ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorFree , <nl> - tensor <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - THDStorage_ ( free ) ( tensor - > storage ) ; <nl> - } <nl> - } <nl> - <nl> - accreal THDTensor_ ( dot ) ( THDTensor * self , THDTensor * src ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorDot , self , src ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < accreal > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - real THDTensor_ ( minall ) ( THDTensor * self ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorMinall , self ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < real > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - real THDTensor_ ( maxall ) ( THDTensor * self ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorMaxall , self ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < real > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - real THDTensor_ ( medianall ) ( THDTensor * self ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorMedianall , self ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < real > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - accreal THDTensor_ ( sumall ) ( THDTensor * self ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorSumall , self ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < accreal > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - accreal THDTensor_ ( prodall ) ( THDTensor * self ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorProdall , self ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < accreal > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( add ) ( THDTensor * self , THDTensor * src , real value ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorAdd , self , src , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( sub ) ( THDTensor * self , THDTensor * src , real value ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorSub , self , src , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( mul ) ( THDTensor * self , THDTensor * src , real value ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorMul , self , src , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( div ) ( THDTensor * self , THDTensor * src , real value ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorDiv , self , src , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( fmod ) ( THDTensor * self , THDTensor * src , real value ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorFmod , self , src , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( remainder ) ( THDTensor * self , THDTensor * src , real value ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorRemainder , self , src , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( clamp ) ( THDTensor * self , THDTensor * src , real min_value , real max_value ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorClamp , self , src , min_value , max_value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cadd ) ( THDTensor * self , THDTensor * src1 , real value , THDTensor * src2 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCadd , self , src1 , src2 , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( csub ) ( THDTensor * self , THDTensor * src1 , real value , THDTensor * src2 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCsub , self , src1 , src2 , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cmul ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCmul , self , src1 , src2 ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cpow ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCpow , self , src1 , src2 ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cdiv ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCdiv , self , src1 , src2 ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cfmod ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCfmod , self , src1 , src2 ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cremainder ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCremainder , self , src1 , src2 ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( addcmul ) ( THDTensor * self , THDTensor * src1 , real value , THDTensor * src2 , THDTensor * src3 ) { <nl> - if ( self ! = src1 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorAddcmul , self , src1 , src2 , src3 , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( addcdiv ) ( THDTensor * self , THDTensor * src1 , real value , THDTensor * src2 , THDTensor * src3 ) { <nl> - if ( self ! = src1 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorAddcdiv , self , src1 , src2 , src3 , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( addmv ) ( THDTensor * self , real beta , THDTensor * src , real alpha , THDTensor * mat , THDTensor * vec ) { <nl> - if ( ( mat - > nDimension ! = 2 ) | | ( vec - > nDimension ! = 1 ) ) <nl> - THError ( " 2D tensor and 1D tensor expected , got % dD , % dD tensors " , mat - > nDimension , vec - > nDimension ) ; <nl> - <nl> - if ( mat - > size [ 1 ] ! = vec - > size [ 0 ] ) { <nl> - THDDescBuff bm = THDTensor_ ( sizeDesc ) ( mat ) ; <nl> - THDDescBuff bv = THDTensor_ ( sizeDesc ) ( vec ) ; <nl> - THError ( " size mismatch , % s , % s " , bm . str , bv . str ) ; <nl> - } <nl> - <nl> - if ( src - > nDimension ! = 1 ) <nl> - THError ( " 1D tensor expected , got src : % dD tensor " , src - > nDimension ) ; <nl> - <nl> - if ( src - > size [ 0 ] ! = mat - > size [ 0 ] ) { <nl> - THDDescBuff bt = THDTensor_ ( sizeDesc ) ( src ) ; <nl> - THDDescBuff bm = THDTensor_ ( sizeDesc ) ( mat ) ; <nl> - THError ( " size mismatch , src : % s , mat : % s " , bt . str , bm . str ) ; <nl> - } <nl> - <nl> - if ( self ! = src ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorAddmv , self , src , mat , vec , beta , alpha ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( addmm ) ( THDTensor * self , real beta , THDTensor * src , real alpha , THDTensor * mat1 , THDTensor * mat2 ) { <nl> - if ( ( mat1 - > nDimension ! = 2 ) | | ( mat2 - > nDimension ! = 2 ) ) <nl> - THError ( " 2D tensors expected , got % dD , % dD tensors " , mat1 - > nDimension , mat2 - > nDimension ) ; <nl> - <nl> - if ( mat1 - > size [ 1 ] ! = mat2 - > size [ 0 ] ) { <nl> - THDDescBuff bm1 = THDTensor_ ( sizeDesc ) ( mat1 ) ; <nl> - THDDescBuff bm2 = THDTensor_ ( sizeDesc ) ( mat2 ) ; <nl> - THError ( " size mismatch , m1 : % s , m2 : % s " , bm1 . str , bm2 . str ) ; <nl> - } <nl> - <nl> - if ( src - > nDimension ! = 2 ) <nl> - THError ( " 2D tensors expected , got % dD tensor for t " , src - > nDimension ) ; <nl> - <nl> - if ( ( src - > size [ 0 ] ! = mat1 - > size [ 0 ] ) | | ( src - > size [ 1 ] ! = mat2 - > size [ 1 ] ) ) { <nl> - THDDescBuff bt = THDTensor_ ( sizeDesc ) ( src ) ; <nl> - THDDescBuff bm1 = THDTensor_ ( sizeDesc ) ( mat1 ) ; <nl> - THDDescBuff bm2 = THDTensor_ ( sizeDesc ) ( mat2 ) ; <nl> - THError ( " size mismatch , t : % s , m1 : % s , m2 : % s " , bt . str , bm1 . str , bm2 . str ) ; <nl> - } <nl> - <nl> - if ( self ! = src ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorAddmm , self , src , mat1 , mat2 , beta , alpha ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( addr ) ( THDTensor * self , real beta , THDTensor * src , real alpha , THDTensor * vec1 , THDTensor * vec2 ) { <nl> - if ( ( vec1 - > nDimension ! = 1 ) | | ( vec2 - > nDimension ! = 1 ) ) <nl> - THError ( " vector and vector expected , got % dD , % dD tensors " , vec1 - > nDimension , vec2 - > nDimension ) ; <nl> - <nl> - if ( src - > nDimension ! = 2 ) <nl> - THError ( " expected matrix , got % dD tensor for t " , src - > nDimension ) ; <nl> - <nl> - if ( ( src - > size [ 0 ] ! = vec1 - > size [ 0 ] ) | | ( src - > size [ 1 ] ! = vec2 - > size [ 0 ] ) ) { <nl> - THDDescBuff bt = THDTensor_ ( sizeDesc ) ( src ) ; <nl> - THDDescBuff bv1 = THDTensor_ ( sizeDesc ) ( vec1 ) ; <nl> - THDDescBuff bv2 = THDTensor_ ( sizeDesc ) ( vec2 ) ; <nl> - THError ( " size mismatch , src : % s , vec1 : % s , vec2 : % s " , bt . str , bv1 . str , bv2 . str ) ; <nl> - } <nl> - <nl> - if ( self ! = src ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorAddr , self , src , vec1 , vec2 , beta , alpha ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( addbmm ) ( THDTensor * self , real beta , THDTensor * src , real alpha , THDTensor * batch1 , THDTensor * batch2 ) { <nl> - THArgCheck ( batch1 - > nDimension = = 3 , 1 , " expected 3D tensor " ) ; <nl> - THArgCheck ( batch2 - > nDimension = = 3 , 2 , " expected 3D tensor " ) ; <nl> - THArgCheck ( batch1 - > size [ 0 ] = = batch2 - > size [ 0 ] , 2 , <nl> - " equal number of batches expected , got % d , % d " , <nl> - batch1 - > size [ 0 ] , batch2 - > size [ 0 ] ) ; <nl> - THArgCheck ( batch1 - > size [ 2 ] = = batch2 - > size [ 1 ] , 2 , <nl> - " wrong matrix size , batch1 : % dx % d , batch2 : % dx % d " , <nl> - batch1 - > size [ 1 ] , batch1 - > size [ 2 ] , batch2 - > size [ 1 ] , batch2 - > size [ 2 ] ) ; <nl> - <nl> - THArgCheck ( src - > size [ 0 ] = = batch1 - > size [ 1 ] , 1 , " output tensor of incorrect size " ) ; <nl> - THArgCheck ( src - > size [ 1 ] = = batch2 - > size [ 2 ] , 1 , " output tensor of incorrect size " ) ; <nl> - <nl> - if ( self ! = src ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorAddbmm , self , src , batch1 , batch2 , beta , alpha ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( baddbmm ) ( THDTensor * self , real beta , THDTensor * src , real alpha , THDTensor * batch1 , THDTensor * batch2 ) { <nl> - THArgCheck ( batch1 - > nDimension = = 3 , 1 , " expected 3D tensor " ) ; <nl> - THArgCheck ( batch2 - > nDimension = = 3 , 2 , " expected 3D tensor " ) ; <nl> - THArgCheck ( batch1 - > size [ 0 ] = = batch2 - > size [ 0 ] , 2 , <nl> - " equal number of batches expected , got % d , % d " , <nl> - batch1 - > size [ 0 ] , batch2 - > size [ 0 ] ) ; <nl> - THArgCheck ( batch1 - > size [ 2 ] = = batch2 - > size [ 1 ] , 2 , <nl> - " wrong matrix size , batch1 : % dx % d , batch2 : % dx % d " , <nl> - batch1 - > size [ 1 ] , batch1 - > size [ 2 ] , batch2 - > size [ 1 ] , batch2 - > size [ 2 ] ) ; <nl> - <nl> - THArgCheck ( src - > size [ 0 ] = = batch1 - > size [ 0 ] , 1 , " output tensor of incorrect size " ) ; <nl> - THArgCheck ( src - > size [ 1 ] = = batch1 - > size [ 1 ] , 1 , " output tensor of incorrect size " ) ; <nl> - THArgCheck ( src - > size [ 2 ] = = batch2 - > size [ 2 ] , 1 , " output tensor of incorrect size " ) ; <nl> - <nl> - if ( self ! = src ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorBaddbmm , self , beta , src , alpha , batch1 , batch2 ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( match ) ( THDTensor * self , THDTensor * m1 , THDTensor * m2 , real gain ) { <nl> - THDTensor_ ( resize2d ) ( self , m1 - > size [ 0 ] , m2 - > size [ 0 ] ) ; <nl> - THArgCheck ( m1 - > size [ 1 ] = = m2 - > size [ 1 ] , 3 , " m1 and m2 must have the same inner vector dim " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorMatch , self , m1 , m2 , gain ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( sum ) ( THDTensor * self , THDTensor * src , int dimension , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < src - > nDimension , 2 , " dimension % d out of range " , <nl> - dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THLongStorage * dim = THDTensor_ ( newSizeOf ) ( src ) ; <nl> - THLongStorage_set ( dim , dimension , 1 ) ; <nl> - THDTensor_ ( resize ) ( self , dim , NULL ) ; <nl> - THLongStorage_free ( dim ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorSum , self , src , dimension , keepdim ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( ! keepdim ) { <nl> - THDTensor_ ( _squeeze1d ) ( self , self , dimension ) ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( prod ) ( THDTensor * self , THDTensor * src , int dimension , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < src - > nDimension , 2 , " dimension % d out of range " , <nl> - dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THLongStorage * dim = THDTensor_ ( newSizeOf ) ( src ) ; <nl> - THLongStorage_set ( dim , dimension , 1 ) ; <nl> - THDTensor_ ( resize ) ( self , dim , NULL ) ; <nl> - THLongStorage_free ( dim ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorProd , self , src , dimension , keepdim ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( ! keepdim ) { <nl> - THDTensor_ ( _squeeze1d ) ( self , self , dimension ) ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( cumsum ) ( THDTensor * self , THDTensor * src , int dimension ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < src - > nDimension , 2 , " dimension % d out of range " , <nl> - dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCumsum , self , src , dimension ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cumprod ) ( THDTensor * self , THDTensor * src , int dimension ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < src - > nDimension , 2 , " dimension % d out of range " , <nl> - dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCumprod , self , src , dimension ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( sign ) ( THDTensor * self , THDTensor * src ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorSign , self , src ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - accreal THDTensor_ ( trace ) ( THDTensor * self ) { <nl> - THArgCheck ( self - > nDimension = = 2 , 1 , " expected a 2D tensor " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorTrace , self ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < accreal > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cross ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 , int dimension ) { <nl> - if ( src1 - > nDimension ! = src2 - > nDimension ) <nl> - THError ( " inconsistent tensor dimension % dD , % dD " , src1 - > nDimension , src2 - > nDimension ) ; <nl> - <nl> - for ( int i = 0 ; i < src1 - > nDimension ; i + + ) { <nl> - if ( src1 - > size [ i ] ! = src2 - > size [ i ] ) { <nl> - THDDescBuff ba = THDTensor_ ( sizeDesc ) ( src1 ) ; <nl> - THDDescBuff bb = THDTensor_ ( sizeDesc ) ( src2 ) ; <nl> - THError ( " inconsistent tensor sizes % s , % s " , ba . str , bb . str ) ; <nl> - } <nl> - } <nl> - <nl> - if ( dimension < 0 ) { <nl> - for ( int i = 0 ; i < src1 - > nDimension ; i + + ) { <nl> - if ( src1 - > size [ i ] = = 3 ) { <nl> - dimension = i ; <nl> - break ; <nl> - } <nl> - } <nl> - <nl> - if ( dimension < 0 ) { <nl> - THDDescBuff ba = THDTensor_ ( sizeDesc ) ( src1 ) ; <nl> - THError ( " no dimension of size 3 in a : % s " , ba . str ) ; <nl> - } <nl> - } <nl> - <nl> - THArgCheck ( dimension > = 0 & & dimension < src1 - > nDimension , 3 , " dimension % d out of range " , <nl> - dimension + TH_INDEX_BASE ) ; <nl> - THArgCheck ( src1 - > size [ dimension ] = = 3 , 3 , " dimension % d does not have size 3 " , <nl> - dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorTrace , self , src1 , src2 , dimension ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cmax ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCmax , self , src1 , src2 ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cmin ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) { <nl> - THDTensor_ ( resizeAs ) ( self , src1 ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCmin , self , src1 , src2 ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cmaxValue ) ( THDTensor * self , THDTensor * src , real value ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCmaxValue , self , src , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cminValue ) ( THDTensor * self , THDTensor * src , real value ) { <nl> - THDTensor_ ( resizeAs ) ( self , src ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCminValue , self , src , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - # endif <nl> deleted file mode 100644 <nl> index edfae81e79bf . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensor . h <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensor . h " <nl> - # else <nl> - <nl> - typedef struct { <nl> - int64_t * size ; <nl> - int64_t * stride ; <nl> - int nDimension ; <nl> - <nl> - THDStorage * storage ; <nl> - ptrdiff_t storageOffset ; <nl> - <nl> - std : : atomic < int > refcount ; <nl> - char flag ; <nl> - <nl> - / / Additional fields <nl> - uint64_t tensor_id ; <nl> - } THDTensor ; <nl> - <nl> - / * * * * helper functions * * * * / <nl> - THD_API THDDescBuff THDTensor_ ( sizeDesc ) ( const THDTensor * tensor ) ; <nl> - <nl> - / * * * * access methods * * * * / <nl> - THD_API THDStorage * THDTensor_ ( storage ) ( const THDTensor * self ) ; <nl> - THD_API ptrdiff_t THDTensor_ ( storageOffset ) ( const THDTensor * self ) ; <nl> - THD_API int THDTensor_ ( nDimensionLegacyNoScalars ) ( const THDTensor * self ) ; <nl> - THD_API int64_t THDTensor_ ( size ) ( const THDTensor * self , int dim ) ; <nl> - THD_API int64_t THDTensor_ ( stride ) ( const THDTensor * self , int dim ) ; <nl> - THD_API THLongStorage * THDTensor_ ( newSizeOf ) ( THDTensor * self ) ; <nl> - THD_API THLongStorage * THDTensor_ ( newStrideOf ) ( THDTensor * self ) ; <nl> - <nl> - THD_API void THDTensor_ ( setFlag ) ( THDTensor * self , char flag ) ; <nl> - THD_API void THDTensor_ ( clearFlag ) ( THDTensor * self , char flag ) ; <nl> - <nl> - <nl> - / * * * * creation methods * * * * / <nl> - THD_API THDTensor * THDTensor_ ( new ) ( void ) ; <nl> - THD_API THDTensor * THDTensor_ ( newWithTensor ) ( THDTensor * tensor ) ; <nl> - / * stride might be NULL * / <nl> - THD_API THDTensor * THDTensor_ ( newWithStorage ) ( THDStorage * storage_ , <nl> - ptrdiff_t storageOffset_ , <nl> - THLongStorage * size_ , <nl> - THLongStorage * stride_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newWithStorage1d ) ( THDStorage * storage_ , <nl> - ptrdiff_t storageOffset_ , <nl> - int64_t size0_ , int64_t stride0_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newWithStorage2d ) ( THDStorage * storage_ , <nl> - ptrdiff_t storageOffset_ , <nl> - int64_t size0_ , int64_t stride0_ , <nl> - int64_t size1_ , int64_t stride1_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newWithStorage3d ) ( THDStorage * storage_ , <nl> - ptrdiff_t storageOffset_ , <nl> - int64_t size0_ , int64_t stride0_ , <nl> - int64_t size1_ , int64_t stride1_ , <nl> - int64_t size2_ , int64_t stride2_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newWithStorage4d ) ( THDStorage * storage_ , <nl> - ptrdiff_t storageOffset_ , <nl> - int64_t size0_ , int64_t stride0_ , <nl> - int64_t size1_ , int64_t stride1_ , <nl> - int64_t size2_ , int64_t stride2_ , <nl> - int64_t size3_ , int64_t stride3_ ) ; <nl> - <nl> - / * stride might be NULL * / <nl> - THD_API THDTensor * THDTensor_ ( newWithSize ) ( THLongStorage * size_ , <nl> - THLongStorage * stride_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newWithSize1d ) ( int64_t size0_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newWithSize2d ) ( int64_t size0_ , int64_t size1_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newWithSize3d ) ( int64_t size0_ , int64_t size1_ , <nl> - int64_t size2_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newWithSize4d ) ( int64_t size0_ , int64_t size1_ , <nl> - int64_t size2_ , int64_t size3_ ) ; <nl> - <nl> - THD_API THDTensor * THDTensor_ ( newClone ) ( THDTensor * self ) ; <nl> - THD_API THDTensor * THDTensor_ ( newContiguous ) ( THDTensor * tensor ) ; <nl> - THD_API THDTensor * THDTensor_ ( newSelect ) ( THDTensor * tensor , int dimension_ , <nl> - int64_t sliceIndex_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newNarrow ) ( THDTensor * tensor , int dimension_ , <nl> - int64_t firstIndex_ , int64_t size_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newTranspose ) ( THDTensor * tensor , int dimension1_ , <nl> - int dimension2_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newUnfold ) ( THDTensor * tensor , int dimension_ , <nl> - int64_t size_ , int64_t step_ ) ; <nl> - THD_API THDTensor * THDTensor_ ( newView ) ( THDTensor * tensor , THLongStorage * size ) ; <nl> - THD_API THDTensor * THDTensor_ ( newExpand ) ( THDTensor * tensor , THLongStorage * size ) ; <nl> - <nl> - THD_API void THDTensor_ ( resize ) ( THDTensor * tensor , THLongStorage * size , <nl> - THLongStorage * stride ) ; <nl> - THD_API void THDTensor_ ( resizeAs ) ( THDTensor * tensor , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( resize1d ) ( THDTensor * tensor , int64_t size0_ ) ; <nl> - THD_API void THDTensor_ ( resize2d ) ( THDTensor * tensor , int64_t size0_ , int64_t size1_ ) ; <nl> - THD_API void THDTensor_ ( resize3d ) ( THDTensor * tensor , int64_t size0_ , int64_t size1_ , <nl> - int64_t size2_ ) ; <nl> - THD_API void THDTensor_ ( resize4d ) ( THDTensor * tensor , int64_t size0_ , int64_t size1_ , <nl> - int64_t size2_ , int64_t size3_ ) ; <nl> - THD_API void THDTensor_ ( resize5d ) ( THDTensor * tensor , int64_t size0_ , int64_t size1_ , <nl> - int64_t size2_ , int64_t size3_ , int64_t size4_ ) ; <nl> - <nl> - THD_API void THDTensor_ ( set ) ( THDTensor * self , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( setStorage ) ( THDTensor * self , THDStorage * storage_ , <nl> - ptrdiff_t storageOffset_ , <nl> - THLongStorage * size_ , <nl> - THLongStorage * stride_ ) ; <nl> - THD_API void THDTensor_ ( setStorage1d ) ( THDTensor * self , THDStorage * storage_ , <nl> - ptrdiff_t storageOffset_ , <nl> - int64_t size0_ , int64_t stride0_ ) ; <nl> - THD_API void THDTensor_ ( setStorage2d ) ( THDTensor * self , THDStorage * storage_ , <nl> - ptrdiff_t storageOffset_ , <nl> - int64_t size0_ , int64_t stride0_ , <nl> - int64_t size1_ , int64_t stride1_ ) ; <nl> - THD_API void THDTensor_ ( setStorage3d ) ( THDTensor * self , THDStorage * storage_ , <nl> - ptrdiff_t storageOffset_ , <nl> - int64_t size0_ , int64_t stride0_ , <nl> - int64_t size1_ , int64_t stride1_ , <nl> - int64_t size2_ , int64_t stride2_ ) ; <nl> - THD_API void THDTensor_ ( setStorage4d ) ( THDTensor * self , THDStorage * storage_ , <nl> - ptrdiff_t storageOffset_ , <nl> - int64_t size0_ , int64_t stride0_ , <nl> - int64_t size1_ , int64_t stride1_ , <nl> - int64_t size2_ , int64_t stride2_ , <nl> - int64_t size3_ , int64_t stride3_ ) ; <nl> - <nl> - THD_API void THDTensor_ ( narrow ) ( THDTensor * self , THDTensor * src , int dimension_ , <nl> - int64_t firstIndex_ , int64_t size_ ) ; <nl> - THD_API void THDTensor_ ( select ) ( THDTensor * self , THDTensor * src , int dimension_ , <nl> - int64_t sliceIndex_ ) ; <nl> - THD_API void THDTensor_ ( transpose ) ( THDTensor * self , THDTensor * src , <nl> - int dimension1_ , int dimension2_ ) ; <nl> - THD_API void THDTensor_ ( unfold ) ( THDTensor * self , THDTensor * src , int dimension_ , <nl> - int64_t size_ , int64_t step_ ) ; <nl> - <nl> - THD_API void THDTensor_ ( squeeze ) ( THDTensor * self , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( squeeze1d ) ( THDTensor * self , THDTensor * src , <nl> - int dimension_ ) ; <nl> - TH_API void THDTensor_ ( unsqueeze1d ) ( THDTensor * self , THDTensor * src , int dimension_ ) ; <nl> - <nl> - THD_API int THDTensor_ ( isContiguous ) ( const THDTensor * self ) ; <nl> - THD_API int THDTensor_ ( isSameSizeAs ) ( const THDTensor * self , const THDTensor * src ) ; <nl> - THD_API int THDTensor_ ( isSetTo ) ( const THDTensor * self , const THDTensor * src ) ; <nl> - THD_API int THDTensor_ ( isSize ) ( const THDTensor * self , const THLongStorage * dims ) ; <nl> - THD_API ptrdiff_t THDTensor_ ( nElement ) ( const THDTensor * self ) ; <nl> - <nl> - THD_API void THDTensor_ ( retain ) ( THDTensor * self ) ; <nl> - THD_API void THDTensor_ ( free ) ( THDTensor * self ) ; <nl> - THD_API void THDTensor_ ( freeCopyTo ) ( THDTensor * self , THDTensor * dst ) ; <nl> - <nl> - / * Slow access methods [ check everything ] * / <nl> - THD_API void THDTensor_ ( set1d ) ( THDTensor * tensor , int64_t x0 , real value ) ; <nl> - THD_API void THDTensor_ ( set2d ) ( THDTensor * tensor , int64_t x0 , int64_t x1 , real value ) ; <nl> - THD_API void THDTensor_ ( set3d ) ( THDTensor * tensor , int64_t x0 , int64_t x1 , <nl> - int64_t x2 , real value ) ; <nl> - THD_API void THDTensor_ ( set4d ) ( THDTensor * tensor , int64_t x0 , int64_t x1 , <nl> - int64_t x2 , int64_t x3 , real value ) ; <nl> - <nl> - THD_API real THDTensor_ ( get1d ) ( const THDTensor * tensor , int64_t x0 ) ; <nl> - THD_API real THDTensor_ ( get2d ) ( const THDTensor * tensor , int64_t x0 , int64_t x1 ) ; <nl> - THD_API real THDTensor_ ( get3d ) ( const THDTensor * tensor , int64_t x0 , int64_t x1 , int64_t x2 ) ; <nl> - THD_API real THDTensor_ ( get4d ) ( const THDTensor * tensor , int64_t x0 , int64_t x1 , <nl> - int64_t x2 , int64_t x3 ) ; <nl> - <nl> - THD_API accreal THDTensor_ ( dot ) ( THDTensor * self , THDTensor * src ) ; <nl> - THD_API real THDTensor_ ( minall ) ( THDTensor * self ) ; <nl> - THD_API real THDTensor_ ( maxall ) ( THDTensor * self ) ; <nl> - THD_API real THDTensor_ ( medianall ) ( THDTensor * self ) ; <nl> - THD_API accreal THDTensor_ ( sumall ) ( THDTensor * self ) ; <nl> - THD_API accreal THDTensor_ ( prodall ) ( THDTensor * self ) ; <nl> - THD_API void THDTensor_ ( neg ) ( THDTensor * self , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( cinv ) ( THDTensor * self , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( add ) ( THDTensor * self , THDTensor * src , real value ) ; <nl> - THD_API void THDTensor_ ( sub ) ( THDTensor * self , THDTensor * src , real value ) ; <nl> - THD_API void THDTensor_ ( mul ) ( THDTensor * self , THDTensor * src , real value ) ; <nl> - THD_API void THDTensor_ ( div ) ( THDTensor * self , THDTensor * src , real value ) ; <nl> - THD_API void THDTensor_ ( fmod ) ( THDTensor * self , THDTensor * src , real value ) ; <nl> - THD_API void THDTensor_ ( remainder ) ( THDTensor * self , THDTensor * src , real value ) ; <nl> - THD_API void THDTensor_ ( clamp ) ( THDTensor * self , THDTensor * src , real min_value , <nl> - real max_value ) ; <nl> - THD_API void THDTensor_ ( cadd ) ( THDTensor * self , THDTensor * src1 , real value , <nl> - THDTensor * src2 ) ; <nl> - THD_API void THDTensor_ ( csub ) ( THDTensor * self , THDTensor * src1 , real value , <nl> - THDTensor * src2 ) ; <nl> - THD_API void THDTensor_ ( cmul ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) ; <nl> - THD_API void THDTensor_ ( cpow ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) ; <nl> - THD_API void THDTensor_ ( cdiv ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) ; <nl> - THD_API void THDTensor_ ( cfmod ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) ; <nl> - THD_API void THDTensor_ ( cremainder ) ( THDTensor * self , THDTensor * src1 , <nl> - THDTensor * src2 ) ; <nl> - THD_API void THDTensor_ ( addcmul ) ( THDTensor * self , THDTensor * src1 , real value , <nl> - THDTensor * src2 , THDTensor * src3 ) ; <nl> - THD_API void THDTensor_ ( addcdiv ) ( THDTensor * self , THDTensor * src1 , real value , <nl> - THDTensor * src2 , THDTensor * src3 ) ; <nl> - THD_API void THDTensor_ ( addmv ) ( THDTensor * self , real beta , THDTensor * src , <nl> - real alpha , THDTensor * mat , THDTensor * vec ) ; <nl> - THD_API void THDTensor_ ( addmm ) ( THDTensor * self , real beta , THDTensor * src , <nl> - real alpha , THDTensor * mat1 , THDTensor * mat2 ) ; <nl> - THD_API void THDTensor_ ( addr ) ( THDTensor * self , real beta , THDTensor * src , <nl> - real alpha , THDTensor * vec1 , THDTensor * vec2 ) ; <nl> - THD_API void THDTensor_ ( addbmm ) ( THDTensor * self , real beta , THDTensor * src , <nl> - real alpha , THDTensor * batch1 , THDTensor * batch2 ) ; <nl> - THD_API void THDTensor_ ( baddbmm ) ( THDTensor * self , real beta , THDTensor * src , <nl> - real alpha , THDTensor * batch1 , THDTensor * batch2 ) ; <nl> - THD_API void THDTensor_ ( match ) ( THDTensor * self , THDTensor * m1 , <nl> - THDTensor * m2 , real gain ) ; <nl> - THD_API void THDTensor_ ( sum ) ( THDTensor * self , THDTensor * src , int dimension , int keepdim ) ; <nl> - THD_API void THDTensor_ ( prod ) ( THDTensor * self , THDTensor * src , int dimension , int keepdim ) ; <nl> - THD_API void THDTensor_ ( cumsum ) ( THDTensor * self , THDTensor * src , int dimension ) ; <nl> - THD_API void THDTensor_ ( cumprod ) ( THDTensor * self , THDTensor * src , int dimension ) ; <nl> - THD_API void THDTensor_ ( sign ) ( THDTensor * self , THDTensor * src ) ; <nl> - THD_API accreal THDTensor_ ( trace ) ( THDTensor * self ) ; <nl> - THD_API void THDTensor_ ( cross ) ( THDTensor * self , THDTensor * src1 , <nl> - THDTensor * src2 , int dimension ) ; <nl> - THD_API void THDTensor_ ( cmax ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) ; <nl> - THD_API void THDTensor_ ( cmin ) ( THDTensor * self , THDTensor * src1 , THDTensor * src2 ) ; <nl> - THD_API void THDTensor_ ( cmaxValue ) ( THDTensor * self , THDTensor * src , real value ) ; <nl> - THD_API void THDTensor_ ( cminValue ) ( THDTensor * self , THDTensor * src , real value ) ; <nl> - <nl> - # endif <nl> deleted file mode 100644 <nl> index 5018461377ac . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensorCopy . cpp <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensorCopy . cpp " <nl> - # else <nl> - <nl> - / / TODO implement <nl> - void THDTensor_ ( copy ) ( THDTensor * tensor , THDTensor * src ) { <nl> - throw std : : runtime_error ( " copy not implemented yet " ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( copyFromMaster ) ( THDTensor * to , THDTensorDescriptor * from ) { <nl> - std : : lock_guard < std : : mutex > guard ( THDState : : s_workers [ THDState : : s_current_worker ] . copy_mutex ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCopyFromMaster , to ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - thd : : dataChannel - > send ( * from , THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( copyFromWorker ) ( THDTensorDescriptor * to , THDTensor * from ) { <nl> - std : : lock_guard < std : : mutex > guard ( THDState : : s_workers [ THDState : : s_current_worker ] . copy_mutex ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCopyFromWorker , from ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - thd : : dataChannel - > receive ( * to , THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - # endif <nl> deleted file mode 100644 <nl> index fc701bc8d4b5 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensorCopy . h <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensorCopy . h " <nl> - # else <nl> - <nl> - THD_API void THDTensor_ ( copy ) ( THDTensor * tensor , THDTensor * src ) ; <nl> - <nl> - THD_API void THDTensor_ ( copyFromMaster ) ( THDTensor * to , THDTensorDescriptor * from ) ; <nl> - THD_API void THDTensor_ ( copyFromWorker ) ( THDTensorDescriptor * to , THDTensor * from ) ; <nl> - <nl> - # endif <nl> deleted file mode 100644 <nl> index 8fac9327b05e . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensorLapack . cpp <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensorLapack . cpp " <nl> - # else <nl> - <nl> - / * <nl> - Check if self is transpose of a contiguous matrix <nl> - * / <nl> - static int THDTensor_ ( isTransposedContiguous ) ( THDTensor * self ) { <nl> - return self - > stride [ 0 ] = = 1 & & self - > stride [ 1 ] = = self - > size [ 0 ] ; <nl> - } <nl> - / * <nl> - If a matrix is a regular contiguous matrix , make sure it is transposed <nl> - because this is what we return from Lapack calls . <nl> - * / <nl> - static void THDTensor_ ( checkTransposed ) ( THDTensor * self ) { <nl> - if ( THDTensor_ ( isContiguous ) ( self ) ) <nl> - THDTensor_ ( transpose ) ( self , NULL , 0 , 1 ) ; <nl> - return ; <nl> - } <nl> - / * <nl> - newContiguous followed by transpose <nl> - Similar to ( newContiguous ) , but checks if the transpose of the matrix <nl> - is contiguous and also limited to 2D matrices . <nl> - * / <nl> - static THDTensor * THDTensor_ ( newTransposedContiguous ) ( THDTensor * self ) { <nl> - THDTensor * tensor ; <nl> - if ( THDTensor_ ( isTransposedContiguous ) ( self ) ) { <nl> - THDTensor_ ( retain ) ( self ) ; <nl> - tensor = self ; <nl> - } else { <nl> - tensor = THDTensor_ ( newContiguous ) ( self ) ; <nl> - THDTensor_ ( transpose ) ( tensor , NULL , 0 , 1 ) ; <nl> - } <nl> - <nl> - return tensor ; <nl> - } <nl> - <nl> - / * <nl> - Given the result tensor and src tensor , decide if the lapack call should use the <nl> - provided result tensor or should allocate a new space to put the result in . <nl> - <nl> - The returned tensor have to be freed by the calling function . <nl> - <nl> - nrows is required , because some lapack calls , require output space smaller than <nl> - input space , like underdetermined gels . <nl> - * / <nl> - static THDTensor * THDTensor_ ( checkLapackClone ) ( THDTensor * result , THDTensor * src , int nrows ) { <nl> - / * check if user wants to reuse src and if it is correct shape / size * / <nl> - if ( src = = result & & THDTensor_ ( isTransposedContiguous ) ( src ) & & src - > size [ 1 ] = = nrows ) <nl> - THDTensor_ ( retain ) ( result ) ; <nl> - else if ( src = = result | | result = = NULL ) <nl> - / * in this case , user wants reuse of src , but its structure is not OK * / <nl> - result = THDTensor_ ( new ) ( ) ; <nl> - else <nl> - THDTensor_ ( retain ) ( result ) ; <nl> - return result ; <nl> - } <nl> - <nl> - / * <nl> - Same as cloneColumnMajor , but accepts nrows argument , because some lapack calls require <nl> - the resulting tensor to be larger than src . <nl> - * / <nl> - static THDTensor * THDTensor_ ( cloneColumnMajorNrows ) ( THDTensor * self , THDTensor * src , int nrows ) { <nl> - THDTensor * result ; <nl> - THDTensor * view ; <nl> - <nl> - if ( src = = NULL ) <nl> - src = self ; <nl> - result = THDTensor_ ( checkLapackClone ) ( self , src , nrows ) ; <nl> - if ( src = = result ) <nl> - return result ; <nl> - <nl> - THDTensor_ ( resize2d ) ( result , src - > size [ 1 ] , nrows ) ; <nl> - THDTensor_ ( checkTransposed ) ( result ) ; <nl> - <nl> - if ( src - > size [ 0 ] = = nrows ) { <nl> - THDTensor_ ( copy ) ( result , src ) ; <nl> - } else { <nl> - view = THDTensor_ ( newNarrow ) ( result , 0 , 0 , src - > size [ 0 ] ) ; <nl> - THDTensor_ ( copy ) ( view , src ) ; <nl> - THDTensor_ ( free ) ( view ) ; <nl> - } <nl> - return result ; <nl> - } <nl> - <nl> - / * <nl> - Create a clone of src in self column major order for use with Lapack . <nl> - If src = = self , a new tensor is allocated , in any case , the return tensor should be <nl> - freed by calling function . <nl> - * / <nl> - static THDTensor * THDTensor_ ( cloneColumnMajor ) ( THDTensor * self , THDTensor * src ) { <nl> - return THDTensor_ ( cloneColumnMajorNrows ) ( self , src , src - > size [ 0 ] ) ; <nl> - } <nl> - <nl> - / * <nl> - * A verbose set of comments on what the Lapack functions do <nl> - * is contained in their implementation in the TH library <nl> - * / <nl> - <nl> - / * TODO this might leak on incorrect data * / <nl> - void THDTensor_ ( gesv ) ( THDTensor * rb , THDTensor * ra , THDTensor * b , THDTensor * a ) { <nl> - bool free_b = false ; <nl> - if ( a = = NULL ) a = ra ; <nl> - if ( b = = NULL ) b = rb ; <nl> - THArgCheck ( a - > nDimension = = 2 , 2 , " A should have 2 dimensions , but has % d " , <nl> - a - > nDimension ) ; <nl> - THArgCheck ( b - > nDimension = = 1 | | b - > nDimension = = 2 , 1 , " B should have 1 or 2 " <nl> - " dimensions , but has % d " , b - > nDimension ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = a - > size [ 1 ] , 2 , " A should be square , but is % ldx % ld " , <nl> - a - > size [ 0 ] , a - > size [ 1 ] ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = b - > size [ 0 ] , 2 , " A , B size incompatible - A has % ld " <nl> - " rows , B has % ld " , a - > size [ 0 ] , b - > size [ 0 ] ) ; <nl> - <nl> - if ( b - > nDimension = = 1 ) { <nl> - b = THDTensor_ ( newWithStorage2d ) ( b - > storage , b - > storageOffset , b - > size [ 0 ] , <nl> - b - > stride [ 0 ] , 1 , 0 ) ; <nl> - free_b = true ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorGesv , rb , ra , b , a ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( ra , a ) ) ; <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( rb , b ) ) ; <nl> - <nl> - if ( free_b ) THDTensor_ ( free ) ( b ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( trtrs ) ( THDTensor * rb , THDTensor * ra , THDTensor * b , THDTensor * a , <nl> - const char * uplo , const char * trans , const char * diag ) { <nl> - bool free_b = false ; <nl> - if ( a = = NULL ) a = ra ; <nl> - if ( b = = NULL ) b = rb ; <nl> - THArgCheck ( a - > nDimension = = 2 , 2 , " A should have 2 dimensions , but has % d " , <nl> - a - > nDimension ) ; <nl> - THArgCheck ( b - > nDimension = = 1 | | b - > nDimension = = 2 , 1 , " B should have 1 or 2 " <nl> - " dimensions , but has % d " , b - > nDimension ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = a - > size [ 1 ] , 2 , " A should be square , but is % ldx % ld " , <nl> - a - > size [ 0 ] , a - > size [ 1 ] ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = b - > size [ 0 ] , 2 , " A , B size incompatible - A has % ld " <nl> - " rows , B has % ld " , a - > size [ 0 ] , b - > size [ 0 ] ) ; <nl> - <nl> - if ( b - > nDimension = = 1 ) { <nl> - b = THDTensor_ ( newWithStorage2d ) ( b - > storage , b - > storageOffset , b - > size [ 0 ] , <nl> - b - > stride [ 0 ] , 1 , 0 ) ; <nl> - free_b = true ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorTrtrs , rb , ra , b , a , uplo [ 0 ] , trans [ 0 ] , diag [ 0 ] ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( ra , a ) ) ; <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( rb , b ) ) ; <nl> - <nl> - if ( free_b ) THDTensor_ ( free ) ( b ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( gels ) ( THDTensor * rb , THDTensor * ra , THDTensor * b , THDTensor * a ) { <nl> - bool free_b = 0 ; <nl> - if ( a = = NULL ) a = ra ; <nl> - if ( b = = NULL ) b = rb ; <nl> - THArgCheck ( a - > nDimension = = 2 , 2 , " A should have 2 dimensions , but has % d " , <nl> - a - > nDimension ) ; <nl> - THArgCheck ( b - > nDimension = = 1 | | b - > nDimension = = 2 , 1 , " B should have 1 or 2 " <nl> - " dimensions , but has % d " , b - > nDimension ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = b - > size [ 0 ] , 2 , " A , B size incompatible - A has % ld " <nl> - " rows , B has % ld " , a - > size [ 0 ] , b - > size [ 0 ] ) ; <nl> - <nl> - if ( b - > nDimension = = 1 ) { <nl> - b = THDTensor_ ( newWithStorage2d ) ( b - > storage , b - > storageOffset , b - > size [ 0 ] , <nl> - b - > stride [ 0 ] , 1 , 0 ) ; <nl> - free_b = true ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorGels , rb , ra , b , a ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - int m , n , nrhs , ldb ; <nl> - <nl> - THDTensor * ra_ = NULL ; <nl> - THDTensor * rb_ = NULL ; <nl> - <nl> - ra_ = THDTensor_ ( cloneColumnMajor ) ( ra , a ) ; <nl> - <nl> - m = ra_ - > size [ 0 ] ; <nl> - n = ra_ - > size [ 1 ] ; <nl> - ldb = ( m > n ) ? m : n ; <nl> - <nl> - rb_ = THDTensor_ ( cloneColumnMajorNrows ) ( rb , b , ldb ) ; <nl> - <nl> - nrhs = rb_ - > size [ 1 ] ; <nl> - <nl> - / * rb_ is currently ldb by nrhs ; resize it to n by nrhs * / <nl> - rb_ - > size [ 0 ] = n ; <nl> - if ( rb_ ! = rb ) <nl> - THDTensor_ ( resize2d ) ( rb , n , nrhs ) ; <nl> - <nl> - THDTensor_ ( free ) ( ra_ ) ; <nl> - THDTensor_ ( free ) ( rb_ ) ; <nl> - if ( free_b ) THDTensor_ ( free ) ( b ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( syev ) ( THDTensor * re , THDTensor * rv , THDTensor * a , <nl> - const char * jobz , const char * uplo ) { <nl> - if ( a = = NULL ) a = rv ; <nl> - THArgCheck ( a - > nDimension = = 2 , 1 , " A should be 2 dimensional " ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = a - > size [ 1 ] , 1 , " A should be square " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorSyev , re , rv , a , jobz [ 0 ] , uplo [ 0 ] ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - THDTensor * rv_ = THDTensor_ ( cloneColumnMajor ) ( rv , a ) ; <nl> - THDTensor_ ( resize1d ) ( re , rv_ - > size [ 0 ] ) ; <nl> - THDTensor_ ( free ) ( rv_ ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( geev ) ( THDTensor * re , THDTensor * rv , THDTensor * a , const char * jobvr ) { <nl> - int n ; <nl> - THDTensor * a_ ; <nl> - <nl> - THDTensor * re_ = NULL ; <nl> - THDTensor * rv_ = NULL ; <nl> - <nl> - THArgCheck ( a - > nDimension = = 2 , 1 , " A should be 2 dimensional " ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = a - > size [ 1 ] , 1 , " A should be square " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorGeev , re , rv , a , jobvr [ 0 ] ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - / * we want to definitely clone a for geev * / <nl> - a_ = THDTensor_ ( cloneColumnMajor ) ( NULL , a ) ; <nl> - <nl> - n = a_ - > size [ 0 ] ; <nl> - <nl> - if ( * jobvr = = ' V ' ) { <nl> - THDTensor_ ( resize2d ) ( rv , n , n ) ; <nl> - / * guard against someone passing a correct size , but wrong stride * / <nl> - rv_ = THDTensor_ ( newTransposedContiguous ) ( rv ) ; <nl> - } <nl> - THDTensor_ ( resize2d ) ( re , n , 2 ) ; <nl> - <nl> - if ( * jobvr = = ' V ' ) { <nl> - THDTensor_ ( checkTransposed ) ( rv ) ; <nl> - } <nl> - <nl> - THDTensor_ ( free ) ( a_ ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( gesvd ) ( THDTensor * ru , THDTensor * rs , THDTensor * rv , THDTensor * a , <nl> - const char * jobu ) { <nl> - THDTensor * ra = THDTensor_ ( new ) ( ) ; <nl> - THDTensor_ ( gesvd2 ) ( ru , rs , rv , ra , a , jobu ) ; <nl> - THDTensor_ ( free ) ( ra ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( gesvd2 ) ( THDTensor * ru , THDTensor * rs , THDTensor * rv , THDTensor * ra , <nl> - THDTensor * a , const char * jobu ) { <nl> - if ( a = = NULL ) a = ra ; <nl> - THArgCheck ( a - > nDimension = = 2 , 1 , " A should be 2 dimensional " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorGesvd2 , ru , rs , rv , ra , a , jobu [ 0 ] ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - int k , m , n , ldu , ldvt ; <nl> - THDTensor * rvf = THDTensor_ ( new ) ( ) ; <nl> - <nl> - THDTensor * ra_ = NULL ; <nl> - THDTensor * ru_ = NULL ; <nl> - <nl> - ra_ = THDTensor_ ( cloneColumnMajor ) ( ra , a ) ; <nl> - <nl> - m = ra_ - > size [ 0 ] ; <nl> - n = ra_ - > size [ 1 ] ; <nl> - k = ( m < n ? m : n ) ; <nl> - <nl> - ldu = m ; <nl> - ldvt = n ; <nl> - <nl> - THDTensor_ ( resize1d ) ( rs , k ) ; <nl> - THDTensor_ ( resize2d ) ( rvf , ldvt , n ) ; <nl> - if ( * jobu = = ' A ' ) <nl> - THDTensor_ ( resize2d ) ( ru , m , ldu ) ; <nl> - else <nl> - THDTensor_ ( resize2d ) ( ru , k , ldu ) ; <nl> - <nl> - THDTensor_ ( checkTransposed ) ( ru ) ; <nl> - <nl> - / * guard against someone passing a correct size , but wrong stride * / <nl> - ru_ = THDTensor_ ( newTransposedContiguous ) ( ru ) ; <nl> - <nl> - if ( * jobu = = ' S ' ) { <nl> - THDTensor_ ( narrow ) ( rvf , NULL , 1 , 0 , k ) ; <nl> - } <nl> - THDTensor_ ( resizeAs ) ( rv , rvf ) ; <nl> - THDTensor_ ( free ) ( rvf ) ; <nl> - THDTensor_ ( free ) ( ra_ ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( getri ) ( THDTensor * ra , THDTensor * a ) { <nl> - if ( a = = NULL ) a = ra ; <nl> - THArgCheck ( a - > nDimension = = 2 , 1 , " A should be 2 dimensional " ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = a - > size [ 1 ] , 1 , " A should be square " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorGetri , ra , a ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( ra , a ) ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( potrf ) ( THDTensor * ra , THDTensor * a , const char * uplo ) { <nl> - if ( a = = NULL ) a = ra ; <nl> - THArgCheck ( a - > nDimension = = 2 , 1 , " A should be 2 dimensional " ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = a - > size [ 1 ] , 1 , " A should be square " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorPotrf , ra , a , uplo [ 0 ] ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( ra , a ) ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( potrs ) ( THDTensor * rb , THDTensor * b , THDTensor * a , const char * uplo ) { <nl> - bool free_b = false ; <nl> - if ( b = = NULL ) b = rb ; <nl> - <nl> - THArgCheck ( a - > nDimension = = 2 , 2 , " A should have 2 dimensions , but has % d " , <nl> - a - > nDimension ) ; <nl> - THArgCheck ( b - > nDimension = = 1 | | b - > nDimension = = 2 , 1 , " B should have 1 or 2 " <nl> - " dimensions , but has % d " , b - > nDimension ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = a - > size [ 1 ] , 2 , " A should be square , but is % ldx % ld " , <nl> - a - > size [ 0 ] , a - > size [ 1 ] ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = b - > size [ 0 ] , 2 , " A , B size incompatible - A has % ld " <nl> - " rows , B has % ld " , a - > size [ 0 ] , b - > size [ 0 ] ) ; <nl> - <nl> - if ( b - > nDimension = = 1 ) { <nl> - b = THDTensor_ ( newWithStorage2d ) ( b - > storage , b - > storageOffset , b - > size [ 0 ] , <nl> - b - > stride [ 0 ] , 1 , 0 ) ; <nl> - free_b = true ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorPotrs , rb , b , a , uplo [ 0 ] ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( NULL , a ) ) ; <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( rb , b ) ) ; <nl> - <nl> - if ( free_b ) THDTensor_ ( free ) ( b ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( potri ) ( THDTensor * ra , THDTensor * a , const char * uplo ) { <nl> - if ( a = = NULL ) a = ra ; <nl> - THArgCheck ( a - > nDimension = = 2 , 1 , " A should be 2 dimensional " ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = a - > size [ 1 ] , 1 , " A should be square " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorPotri , ra , a , uplo [ 0 ] ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( ra , a ) ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( qr ) ( THDTensor * rq , THDTensor * rr , THDTensor * a ) { <nl> - int m = a - > size [ 0 ] ; <nl> - int n = a - > size [ 1 ] ; <nl> - int k = ( m < n ? m : n ) ; <nl> - THDTensor * ra = THDTensor_ ( new ) ( ) ; <nl> - THDTensor * rtau = THDTensor_ ( new ) ( ) ; <nl> - THDTensor * rr_ = THDTensor_ ( new ) ( ) ; <nl> - THDTensor_ ( geqrf ) ( ra , rtau , a ) ; <nl> - THDTensor_ ( resize2d ) ( rr_ , k , ra - > size [ 1 ] ) ; <nl> - THDTensor_ ( narrow ) ( rr_ , ra , 0 , 0 , k ) ; <nl> - THDTensor_ ( triu ) ( rr_ , rr_ , 0 ) ; <nl> - THDTensor_ ( resize2d ) ( rq , ra - > size [ 0 ] , k ) ; <nl> - THDTensor_ ( orgqr ) ( rq , ra , rtau ) ; <nl> - THDTensor_ ( narrow ) ( rq , rq , 1 , 0 , k ) ; <nl> - THDTensor_ ( free ) ( ra ) ; <nl> - THDTensor_ ( free ) ( rtau ) ; <nl> - THDTensor_ ( free ) ( rr_ ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( geqrf ) ( THDTensor * ra , THDTensor * rtau , THDTensor * a ) { <nl> - if ( a = = NULL ) ra = a ; <nl> - THArgCheck ( a - > nDimension = = 2 , 1 , " A should be 2 dimensional " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorGeqrf , ra , rtau , a ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - THDTensor * ra_ = THDTensor_ ( cloneColumnMajor ) ( ra , a ) ; <nl> - <nl> - int m = ra_ - > size [ 0 ] ; <nl> - int n = ra_ - > size [ 1 ] ; <nl> - int k = ( m < n ? m : n ) ; <nl> - THDTensor_ ( resize1d ) ( rtau , k ) ; <nl> - THDTensor_ ( free ) ( ra ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( orgqr ) ( THDTensor * ra , THDTensor * a , THDTensor * tau ) { <nl> - if ( a = = NULL ) a = ra ; <nl> - THArgCheck ( a - > nDimension = = 2 , 1 , " A should be 2 dimensional " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorOrgqr , ra , a ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( ra , a ) ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( ormqr ) ( THDTensor * ra , THDTensor * a , THDTensor * tau , THDTensor * c , <nl> - const char * side , const char * trans ) { <nl> - if ( a = = NULL ) a = ra ; <nl> - THArgCheck ( a - > nDimension = = 2 , 1 , " A should be 2 dimensional " ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorOrmqr , ra , a , tau , c , side [ 0 ] , trans [ 0 ] ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - THDTensor_ ( free ) ( THDTensor_ ( cloneColumnMajor ) ( ra , c ) ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( pstrf ) ( THDTensor * ra , THDIntTensor * rpiv , THDTensor * a , <nl> - const char * uplo , real tol ) { <nl> - THArgCheck ( a - > nDimension = = 2 , 1 , " A should be 2 dimensional " ) ; <nl> - THArgCheck ( a - > size [ 0 ] = = a - > size [ 1 ] , 1 , " A should be square " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorPstrf , ra , rpiv , a , uplo [ 0 ] , tol ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - int n = a - > size [ 0 ] ; <nl> - <nl> - THDTensor * ra_ = THDTensor_ ( cloneColumnMajor ) ( ra , a ) ; <nl> - THDIntTensor_resize1d ( rpiv , n ) ; <nl> - <nl> - THDTensor_ ( free ) ( ra_ ) ; <nl> - } <nl> - <nl> - # endif <nl> deleted file mode 100644 <nl> index d5c8f2174e0f . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensorLapack . h <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensorLapack . h " <nl> - # else <nl> - <nl> - THD_API void THDTensor_ ( gesv ) ( THDTensor * rb_ , THDTensor * ra_ , THDTensor * b_ , THDTensor * a_ ) ; <nl> - THD_API void THDTensor_ ( trtrs ) ( THDTensor * rb_ , THDTensor * ra_ , THDTensor * b_ , THDTensor * a_ , <nl> - const char * uplo , const char * trans , const char * diag ) ; <nl> - THD_API void THDTensor_ ( gels ) ( THDTensor * rb_ , THDTensor * ra_ , THDTensor * b_ , THDTensor * a_ ) ; <nl> - THD_API void THDTensor_ ( syev ) ( THDTensor * re_ , THDTensor * rv_ , THDTensor * a_ , <nl> - const char * jobz , const char * uplo ) ; <nl> - THD_API void THDTensor_ ( geev ) ( THDTensor * re_ , THDTensor * rv_ , THDTensor * a_ , const char * jobvr ) ; <nl> - THD_API void THDTensor_ ( gesvd ) ( THDTensor * ru_ , THDTensor * rs_ , THDTensor * rv_ , THDTensor * a , <nl> - const char * jobu ) ; <nl> - THD_API void THDTensor_ ( gesvd2 ) ( THDTensor * ru_ , THDTensor * rs_ , THDTensor * rv_ , THDTensor * ra_ , <nl> - THDTensor * a , const char * jobu ) ; <nl> - THD_API void THDTensor_ ( getri ) ( THDTensor * ra_ , THDTensor * a ) ; <nl> - THD_API void THDTensor_ ( potrf ) ( THDTensor * ra_ , THDTensor * a , const char * uplo ) ; <nl> - THD_API void THDTensor_ ( potrs ) ( THDTensor * rb_ , THDTensor * b_ , THDTensor * a_ , const char * uplo ) ; <nl> - THD_API void THDTensor_ ( potri ) ( THDTensor * ra_ , THDTensor * a , const char * uplo ) ; <nl> - THD_API void THDTensor_ ( qr ) ( THDTensor * rq_ , THDTensor * rr_ , THDTensor * a ) ; <nl> - THD_API void THDTensor_ ( geqrf ) ( THDTensor * ra_ , THDTensor * rtau_ , THDTensor * a ) ; <nl> - THD_API void THDTensor_ ( orgqr ) ( THDTensor * ra_ , THDTensor * a , THDTensor * tau ) ; <nl> - THD_API void THDTensor_ ( ormqr ) ( THDTensor * ra_ , THDTensor * a , THDTensor * tau , THDTensor * c , <nl> - const char * side , const char * trans ) ; <nl> - THD_API void THDTensor_ ( pstrf ) ( THDTensor * ra_ , THDIntTensor * rpiv_ , THDTensor * a , <nl> - const char * uplo , real tol ) ; <nl> - # endif <nl> deleted file mode 100644 <nl> index 4a5371e3dde2 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensorMath . cpp <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensorMath . cpp " <nl> - # else <nl> - <nl> - using namespace thd ; <nl> - using namespace rpc ; <nl> - using namespace master ; <nl> - <nl> - void THDTensor_ ( gather ) ( THDTensor * self , THDTensor * src , int dim , THDLongTensor * index ) { <nl> - THArgCheck ( dim < self - > nDimension , 2 , " Index dimension is out of bounds " ) ; <nl> - THArgCheck ( THDLongTensor_nDimensionLegacyNoScalars ( index ) = = self - > nDimension , 3 , <nl> - " Index tensor must have same dimensions as output tensor " ) ; <nl> - THArgCheck ( src - > nDimension = = self - > nDimension , 4 , <nl> - " Input tensor must have same dimensions as output tensor " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorGather , <nl> - self , <nl> - src , <nl> - dim , <nl> - index <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( scatter ) ( THDTensor * self , int dim , THDLongTensor * index , THDTensor * src ) { <nl> - THArgCheck ( dim < self - > nDimension , 2 , " Index dimension is out of bounds " ) ; <nl> - THArgCheck ( THDLongTensor_nDimensionLegacyNoScalars ( index ) = = self - > nDimension , 3 , <nl> - " Index tensor must have same dimensions as output tensor " ) ; <nl> - THArgCheck ( src - > nDimension = = self - > nDimension , 4 , <nl> - " Input tensor must have same dimensions as output tensor " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorScatter , <nl> - self , <nl> - dim , <nl> - index , <nl> - src <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( scatterFill ) ( THDTensor * self , int dim , THDLongTensor * index , real val ) { <nl> - THArgCheck ( dim < self - > nDimension , 2 , " Index dimension is out of bounds " ) ; <nl> - THArgCheck ( THDLongTensor_nDimensionLegacyNoScalars ( index ) = = self - > nDimension , 3 , <nl> - " Index tensor must have same dimensions as output tensor " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorScatterFill , <nl> - self , <nl> - dim , <nl> - index , <nl> - val <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - THD_API void THDTensor_ ( scatterAdd ) ( THDTensor * self , int dim , THDLongTensor * index , <nl> - THDTensor * src ) { <nl> - THError ( " scatterAdd not implemented " ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( max ) ( THDTensor * self , THDLongTensor * indices_ , THDTensor * src , int dimension , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < src - > nDimension , 2 , " dimension % d out of range " , <nl> - dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THLongStorage * dim = THDTensor_ ( newSizeOf ) ( src ) ; <nl> - THLongStorage_set ( dim , dimension , 1 ) ; <nl> - THDTensor_ ( resize ) ( self , dim , NULL ) ; <nl> - THDLongTensor_resize ( indices_ , dim , NULL ) ; <nl> - THLongStorage_free ( dim ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorMax , self , indices_ , src , dimension , keepdim ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( ! keepdim ) { <nl> - THDTensor_ ( _squeeze1d ) ( self , self , dimension ) ; <nl> - THDLongTensor__squeeze1d ( indices_ , indices_ , dimension ) ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( min ) ( THDTensor * self , THDLongTensor * indices_ , THDTensor * src , int dimension , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < src - > nDimension , 2 , " dimension % d out of range " , <nl> - dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THLongStorage * dim = THDTensor_ ( newSizeOf ) ( src ) ; <nl> - THLongStorage_set ( dim , dimension , 1 ) ; <nl> - THDTensor_ ( resize ) ( self , dim , NULL ) ; <nl> - THDLongTensor_resize ( indices_ , dim , NULL ) ; <nl> - THLongStorage_free ( dim ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorMin , self , indices_ , src , dimension , keepdim ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( ! keepdim ) { <nl> - THDTensor_ ( _squeeze1d ) ( self , self , dimension ) ; <nl> - THDLongTensor__squeeze1d ( indices_ , indices_ , dimension ) ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( kthvalue ) ( THDTensor * self , THDLongTensor * indices_ , THDTensor * src , int64_t k , int dimension , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < src - > nDimension , 3 , " dimension out of range " ) ; <nl> - THArgCheck ( k > 0 & & k < = src - > size [ dimension ] , 2 , " selected index out of range " ) ; <nl> - <nl> - THLongStorage * dim = THDTensor_ ( newSizeOf ) ( src ) ; <nl> - THLongStorage_set ( dim , dimension , 1 ) ; <nl> - THDTensor_ ( resize ) ( self , dim , NULL ) ; <nl> - THDLongTensor_resize ( indices_ , dim , NULL ) ; <nl> - THLongStorage_free ( dim ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorKthvalue , self , indices_ , src , k , dimension , keepdim ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( ! keepdim ) { <nl> - THDTensor_ ( _squeeze1d ) ( self , self , dimension ) ; <nl> - THDLongTensor__squeeze1d ( indices_ , indices_ , dimension ) ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( mode ) ( THDTensor * self , THDLongTensor * indices_ , THDTensor * src , int dimension , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < src - > nDimension , 3 , " dimension out of range " ) ; <nl> - <nl> - THLongStorage * dim = THDTensor_ ( newSizeOf ) ( src ) ; <nl> - THLongStorage_set ( dim , dimension , 1 ) ; <nl> - THDTensor_ ( resize ) ( self , dim , NULL ) ; <nl> - THDLongTensor_resize ( indices_ , dim , NULL ) ; <nl> - THLongStorage_free ( dim ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorMode , self , indices_ , src , dimension , keepdim ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( ! keepdim ) { <nl> - THDTensor_ ( _squeeze1d ) ( self , self , dimension ) ; <nl> - THDLongTensor__squeeze1d ( indices_ , indices_ , dimension ) ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( median ) ( THDTensor * self , THDLongTensor * indices_ , THDTensor * src , int dimension , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < src - > nDimension , 3 , " dimension out of range " ) ; <nl> - <nl> - int64_t t_size_dim = src - > size [ dimension ] ; <nl> - int64_t k = ( t_size_dim - 1 ) > > 1 ; / * take middle or one - before - middle element * / <nl> - <nl> - THDTensor_ ( kthvalue ) ( self , indices_ , src , k + 1 , dimension , keepdim ) ; <nl> - } <nl> - <nl> - <nl> - void THDTensor_ ( fill ) ( THDTensor * tensor , real value ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorFill , <nl> - tensor , <nl> - value <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( zero ) ( THDTensor * r ) { <nl> - THDTensor_ ( fill ) ( r , 0 ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( maskedFill ) ( THDTensor * tensor , THDByteTensor * mask , real value ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorMaskedFill , <nl> - tensor , <nl> - mask , <nl> - value <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( maskedCopy ) ( THDTensor * tensor , THDByteTensor * mask , THDTensor * src ) { <nl> - if ( THDTensor_ ( nElement ) ( tensor ) ! = THDByteTensor_nElement ( mask ) ) <nl> - THError ( " Number of elements of destination tensor ! = Number of elements in mask " ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorMaskedCopy , <nl> - tensor , <nl> - mask , <nl> - src <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( maskedSelect ) ( THDTensor * tensor , THDTensor * src , THDByteTensor * mask ) { <nl> - ptrdiff_t numel = THDByteTensor_sumall ( mask ) ; <nl> - THDTensor_ ( resize1d ) ( tensor , numel ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorMaskedSelect , <nl> - tensor , <nl> - src , <nl> - mask <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( nonzero ) ( THDLongTensor * subscript , THDTensor * tensor ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorNonzero , <nl> - subscript , <nl> - tensor <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - int64_t numel = receiveValueFromWorker < int64_t > ( tensor - > storage - > node_id ) ; <nl> - THDLongTensor__resize2d ( subscript , numel , tensor - > nDimension ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( indexSelect ) ( THDTensor * tensor , THDTensor * src , int dim , THDLongTensor * index ) { <nl> - THArgCheck ( index - > nDimension = = 1 , 3 , " Index is supposed to be a vector " ) ; <nl> - THArgCheck ( dim < src - > nDimension , 4 , " Indexing dim % d is out of bounds of tensor " , <nl> - dim + TH_INDEX_BASE ) ; <nl> - THArgCheck ( src - > nDimension > 0 , 2 , " Source tensor is empty " ) ; <nl> - THLongStorage * newSize = THLongStorage_newWithSize ( src - > nDimension ) ; <nl> - THLongStorage_rawCopy ( newSize , src - > size ) ; <nl> - THDTensor_ ( resize ) ( tensor , newSize , NULL ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorIndexSelect , <nl> - tensor , <nl> - src , <nl> - dim , <nl> - index <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( indexCopy ) ( THDTensor * tensor , int dim , THDLongTensor * index , THDTensor * src ) { <nl> - ptrdiff_t numel = THDLongTensor_nElement ( index ) ; <nl> - THArgCheck ( index - > nDimension = = 1 , 3 , " Index is supposed to be a vector " ) ; <nl> - THArgCheck ( dim < src - > nDimension , 4 , " Indexing dim % d is out of bounds of tensor " , <nl> - dim + TH_INDEX_BASE ) ; <nl> - THArgCheck ( numel = = src - > size [ dim ] , 4 , " Number of indices should be equal to source : size ( dim ) " ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorIndexCopy , <nl> - tensor , <nl> - dim , <nl> - index , <nl> - src <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( indexAdd ) ( THDTensor * tensor , int dim , THDLongTensor * index , THDTensor * src ) { <nl> - ptrdiff_t numel = THDLongTensor_nElement ( index ) ; <nl> - THArgCheck ( index - > nDimension = = 1 , 3 , " Index is supposed to be a vector " ) ; <nl> - THArgCheck ( dim < src - > nDimension , 4 , " Indexing dim % d is out of bounds of tensor " , <nl> - dim + TH_INDEX_BASE ) ; <nl> - THArgCheck ( numel = = src - > size [ dim ] , 4 , " Number of indices should be equal to source : size ( dim ) " ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorIndexAdd , <nl> - tensor , <nl> - dim , <nl> - index , <nl> - src <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( indexFill ) ( THDTensor * tensor , int dim , THDLongTensor * index , real val ) { <nl> - ptrdiff_t numel = THDLongTensor_nElement ( index ) ; <nl> - THArgCheck ( index - > nDimension = = 1 , 3 , " Index is supposed to be a vector " ) ; <nl> - THArgCheck ( dim < tensor - > nDimension , 4 , " Indexing dim % d is out of bounds of tensor " , <nl> - dim + TH_INDEX_BASE ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorIndexFill , <nl> - tensor , <nl> - dim , <nl> - index , <nl> - val <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( zeros ) ( THDTensor * tensor , THLongStorage * size ) { <nl> - THDTensor_ ( resize ) ( tensor , size , nullptr ) ; <nl> - THDTensor_ ( zero ) ( tensor ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( ones ) ( THDTensor * tensor , THLongStorage * size ) { <nl> - THDTensor_ ( resize ) ( tensor , size , nullptr ) ; <nl> - THDTensor_ ( fill ) ( tensor , 1 ) ; <nl> - } <nl> - <nl> - ptrdiff_t THDTensor_ ( numel ) ( THDTensor * t ) { <nl> - return THDTensor_ ( nElement ) ( t ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( diag ) ( THDTensor * r_ , THDTensor * t , int k ) { <nl> - THArgCheck ( THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) = = 1 | | THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) = = 2 , <nl> - 1 , " matrix or a vector expected " ) ; <nl> - <nl> - if ( THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) = = 1 ) { <nl> - int64_t t_size = THDTensor_ ( size ) ( t , 0 ) ; <nl> - int64_t sz = t_size + ( k > = 0 ? k : - k ) ; <nl> - <nl> - THDTensor_ ( resize2d ) ( r_ , sz , sz ) ; <nl> - THDTensor_ ( zero ) ( r_ ) ; <nl> - } else { <nl> - int64_t sz ; <nl> - if ( k > = 0 ) <nl> - sz = std : : min ( THDTensor_ ( size ) ( t , 0 ) , THDTensor_ ( size ) ( t , 1 ) - k ) ; <nl> - else <nl> - sz = std : : min ( THDTensor_ ( size ) ( t , 0 ) + k , THDTensor_ ( size ) ( t , 1 ) ) ; <nl> - THDTensor_ ( resize1d ) ( r_ , sz ) ; <nl> - } <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorDiag , r_ , t , k ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( eye ) ( THDTensor * r , int64_t n , int64_t m ) { <nl> - THArgCheck ( n > 0 , 1 , " invalid argument " ) ; <nl> - <nl> - if ( m < = 0 ) <nl> - m = n ; <nl> - <nl> - THDTensor_ ( resize2d ) ( r , n , m ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorEye , r , n , m ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - <nl> - void THDTensor_ ( range ) ( THDTensor * r_ , accreal xmin , <nl> - accreal xmax , accreal step ) { <nl> - THArgCheck ( step > 0 | | step < 0 , 3 , " step must be a non - null number " ) ; <nl> - THArgCheck ( ( ( step > 0 ) & & ( xmax > = xmin ) ) | | ( ( step < 0 ) & & ( xmax < = xmin ) ) , <nl> - 2 , " upper bound and larger bound incoherent with step sign " ) ; <nl> - <nl> - ptrdiff_t size = static_cast < ptrdiff_t > ( ( ( ( xmax - xmin ) / step ) + 1 ) ) ; <nl> - <nl> - if ( THDTensor_ ( nElement ) ( r_ ) ! = size ) <nl> - THDTensor_ ( resize1d ) ( r_ , size ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorRange , r_ , xmin , xmax , step ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( randperm ) ( THDTensor * r_ , THDGenerator * _generator , int64_t n ) { <nl> - THArgCheck ( n > 0 , 1 , " must be strictly positive " ) ; <nl> - THDTensor_ ( resize1d ) ( r_ , n ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorRange , r_ , _generator , n ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( reshape ) ( THDTensor * r_ , THDTensor * t , THLongStorage * size ) { <nl> - THDTensor_ ( resize ) ( r_ , size , NULL ) ; <nl> - THDTensor_ ( copy ) ( r_ , t ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( sort ) ( THDTensor * rt_ , THDLongTensor * ri_ , <nl> - THDTensor * t , int dimension , <nl> - int descendingOrder ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) , <nl> - 2 , " invalid dimension % d " , dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THDTensor_ ( resizeAs ) ( rt_ , t ) ; <nl> - THDTensor_ ( copy ) ( rt_ , t ) ; <nl> - <nl> - { <nl> - THLongStorage * size = THDTensor_ ( newSizeOf ) ( t ) ; <nl> - THDLongTensor_resize ( ri_ , size , NULL ) ; <nl> - THLongStorage_free ( size ) ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorSort , rt_ , ri_ , t , dimension , descendingOrder ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( topk ) ( THDTensor * rt_ , THDLongTensor * ri_ , <nl> - THDTensor * t , int64_t k , int dim , <nl> - int dir , int sorted ) { <nl> - int numDims = THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) ; <nl> - THArgCheck ( dim > = 0 & & dim < numDims , 3 , " dim not in range " ) ; <nl> - <nl> - int64_t sliceSize = THDTensor_ ( size ) ( t , dim ) ; <nl> - THArgCheck ( k > 0 & & k < = sliceSize , 2 , " k not in range for dimension " ) ; <nl> - <nl> - THLongStorage * topKSize = THDTensor_ ( newSizeOf ) ( t ) ; <nl> - THLongStorage_set ( topKSize , dim , k ) ; <nl> - THDTensor_ ( resize ) ( rt_ , topKSize , NULL ) ; <nl> - THDLongTensor_resize ( ri_ , topKSize , NULL ) ; <nl> - THLongStorage_free ( topKSize ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorTopk , rt_ , ri_ , t , k , dim , dir , sorted ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( tril ) ( THDTensor * r_ , THDTensor * t , int64_t k ) { <nl> - THArgCheck ( THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) = = 2 , 1 , " expected a matrix " ) ; <nl> - <nl> - THDTensor_ ( resizeAs ) ( r_ , t ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorTril , r_ , t , k ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( triu ) ( THDTensor * r_ , THDTensor * t , int64_t k ) { <nl> - THArgCheck ( THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) = = 2 , 1 , " expected a matrix " ) ; <nl> - <nl> - THDTensor_ ( resizeAs ) ( r_ , t ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorTriu , r_ , t , k ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - void THDTensor_ ( cat ) ( THDTensor * r_ , THDTensor * ta , THDTensor * tb , int dimension ) { <nl> - THDTensor * inputs [ 2 ] ; <nl> - inputs [ 0 ] = ta ; <nl> - inputs [ 1 ] = tb ; <nl> - THDTensor_ ( catArray ) ( r_ , inputs , 2 , dimension ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( catArray ) ( THDTensor * result , THDTensor * * inputs , <nl> - int numInputs , int dimension ) { <nl> - THLongStorage * size ; <nl> - int64_t offset ; <nl> - int ndim = dimension + 1 ; <nl> - int ldimension = dimension ; <nl> - bool allEmpty = true ; <nl> - for ( int i = 0 ; i < numInputs ; i + + ) <nl> - ndim = std : : max ( ndim , inputs [ i ] - > nDimension ) ; <nl> - <nl> - if ( dimension = = - 2 ) <nl> - ldimension = ndim ? ( ndim - 1 ) : 0 ; <nl> - <nl> - THArgCheck ( numInputs > 0 , 3 , " invalid number of inputs % d " , numInputs ) ; <nl> - THArgCheck ( ldimension > = 0 , 4 , " invalid dimension % d " , dimension + TH_INDEX_BASE ) ; <nl> - <nl> - size = THLongStorage_newWithSize ( ndim ) ; <nl> - <nl> - for ( int i = 0 ; i < ndim ; i + + ) { <nl> - int64_t dimSize = i < inputs [ 0 ] - > nDimension ? <nl> - inputs [ 0 ] - > size [ i ] : <nl> - std : : min ( inputs [ 0 ] - > nDimension , 1 ) ; <nl> - if ( i = = ldimension ) { <nl> - for ( int j = 1 ; j < numInputs ; j + + ) { <nl> - dimSize + = i < inputs [ j ] - > nDimension ? <nl> - inputs [ j ] - > size [ i ] : <nl> - std : : min ( inputs [ j ] - > nDimension , 1 ) ; <nl> - } <nl> - } else { <nl> - for ( int j = 1 ; j < numInputs ; j + + ) { <nl> - int64_t sz = i < inputs [ j ] - > nDimension ? <nl> - inputs [ j ] - > size [ i ] : <nl> - std : : min ( inputs [ j ] - > nDimension , 1 ) ; <nl> - if ( dimSize ! = sz & & dimSize & & sz ) { <nl> - THLongStorage_free ( size ) ; <nl> - THError ( " inconsistent tensor sizes " ) ; <nl> - } else if ( ! dimSize ) { <nl> - dimSize = sz ; <nl> - } <nl> - } <nl> - } <nl> - allEmpty = allEmpty & & ! dimSize ; <nl> - THLongStorage_set ( size , i , dimSize ) ; <nl> - } <nl> - <nl> - if ( ! allEmpty ) { <nl> - THDTensor_ ( resize ) ( result , size , NULL ) ; <nl> - std : : vector < THDTensor * > inputs_vec ( inputs , inputs + numInputs ) ; <nl> - <nl> - / / There ' s no need to send numInputs , <nl> - / / since sending inputs_vec does this implicitly <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCatArray , result , inputs_vec , dimension ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - THLongStorage_free ( size ) ; <nl> - } <nl> - <nl> - int THDTensor_ ( equal ) ( THDTensor * ta , THDTensor * tb ) { <nl> - if ( ! THDTensor_ ( isSameSizeAs ) ( ta , tb ) ) <nl> - return 0 ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorEqual , ta , tb ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - return receiveValueFromWorker < int > ( ta - > storage - > node_id ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( tpow ) ( THDTensor * r_ , real value , THDTensor * t ) { <nl> - THDTensor_ ( resizeAs ) ( r_ , t ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorEqual , r_ , t , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - # define TENSOR_IMPLEMENT_LOGICAL ( NAME , UPPNAME ) \ <nl> - void THDTensor_ ( NAME # # Value ) ( THDByteTensor * r_ , THDTensor * t , real value ) { \ <nl> - THDByteTensor__resize ( r_ , t - > nDimension , t - > size , NULL ) ; \ <nl> - masterCommandChannel - > sendMessage ( \ <nl> - packMessage ( Functions : : tensor # # UPPNAME # # Value , r_ , t , value ) , \ <nl> - THDState : : s_current_worker \ <nl> - ) ; \ <nl> - } \ <nl> - void THDTensor_ ( NAME # # ValueT ) ( THDTensor * r_ , THDTensor * t , real value ) { \ <nl> - THDTensor_ ( _resize ) ( r_ , t - > nDimension , t - > size , NULL ) ; \ <nl> - masterCommandChannel - > sendMessage ( \ <nl> - packMessage ( Functions : : tensor # # UPPNAME # # ValueT , r_ , t , value ) , \ <nl> - THDState : : s_current_worker \ <nl> - ) ; \ <nl> - } \ <nl> - void THDTensor_ ( NAME # # Tensor ) ( THDByteTensor * r_ , THDTensor * ta , THDTensor * tb ) { \ <nl> - THDByteTensor__resize ( r_ , ta - > nDimension , ta - > size , NULL ) ; \ <nl> - masterCommandChannel - > sendMessage ( \ <nl> - packMessage ( Functions : : tensor # # UPPNAME # # Tensor , r_ , ta , tb ) , \ <nl> - THDState : : s_current_worker \ <nl> - ) ; \ <nl> - } \ <nl> - void THDTensor_ ( NAME # # TensorT ) ( THDTensor * r_ , THDTensor * ta , THDTensor * tb ) { \ <nl> - THDTensor_ ( _resize ) ( r_ , ta - > nDimension , ta - > size , NULL ) ; \ <nl> - masterCommandChannel - > sendMessage ( \ <nl> - packMessage ( Functions : : tensor # # UPPNAME # # TensorT , r_ , ta , tb ) , \ <nl> - THDState : : s_current_worker \ <nl> - ) ; \ <nl> - } \ <nl> - <nl> - <nl> - TENSOR_IMPLEMENT_LOGICAL ( lt , Lt ) <nl> - TENSOR_IMPLEMENT_LOGICAL ( gt , Lt ) <nl> - TENSOR_IMPLEMENT_LOGICAL ( le , Le ) <nl> - TENSOR_IMPLEMENT_LOGICAL ( ge , Ge ) <nl> - TENSOR_IMPLEMENT_LOGICAL ( eq , Eq ) <nl> - TENSOR_IMPLEMENT_LOGICAL ( ne , Ne ) <nl> - <nl> - # undef TENSOR_IMPLEMENT_LOGICAL <nl> - <nl> - # define TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( NAME , UPPNAME ) \ <nl> - void THDTensor_ ( NAME ) ( THDTensor * r_ , THDTensor * t ) { \ <nl> - THDTensor_ ( resizeAs ) ( r_ , t ) ; \ <nl> - masterCommandChannel - > sendMessage ( \ <nl> - packMessage ( Functions : : tensor # # UPPNAME , r_ , t ) , \ <nl> - THDState : : s_current_worker \ <nl> - ) ; \ <nl> - } \ <nl> - <nl> - # define TENSOR_IMPLEMENT_POINTWISE_VALUE_FUNCTION ( NAME , UPPNAME ) \ <nl> - void THDTensor_ ( NAME ) ( THDTensor * r_ , THDTensor * t , real value ) { \ <nl> - THDTensor_ ( resizeAs ) ( r_ , t ) ; \ <nl> - masterCommandChannel - > sendMessage ( \ <nl> - packMessage ( Functions : : tensor # # UPPNAME , r_ , t , value ) , \ <nl> - THDState : : s_current_worker \ <nl> - ) ; \ <nl> - } \ <nl> - <nl> - <nl> - # if defined ( TH_REAL_IS_LONG ) | | defined ( TH_REAL_IS_INT ) | | \ <nl> - defined ( TH_REAL_IS_DOUBLE ) | | defined ( TH_REAL_IS_FLOAT ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( abs , Abs ) <nl> - # endif <nl> - <nl> - # if defined ( TH_REAL_IS_DOUBLE ) | | defined ( TH_REAL_IS_FLOAT ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( sigmoid , Sigmoid ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( log , Log ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( log10 , Log10 ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( log1p , Log1p ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( log2 , Log2 ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( exp , Exp ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( expm1 , Expm1 ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( cos , Cos ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( acos , Acos ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( cosh , Cosh ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( sin , Sin ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( asin , Asin ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( sinh , Sinh ) <nl> - <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( tan , Tan ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( atan , Atan ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( tanh , Tanh ) <nl> - TENSOR_IMPLEMENT_POINTWISE_VALUE_FUNCTION ( pow , Pow ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( sqrt , Sqrt ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( rsqrt , Rsqrt ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( ceil , Ceil ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( floor , Floor ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( round , Round ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( trunc , Trunc ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( frac , Frac ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( neg , Neg ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( cinv , Cinv ) <nl> - <nl> - # undef TENSOR_IMPLEMENT_POINTWISE_VALUE_FUNCTION <nl> - # undef TENSOR_IMPLEMENT_POINTWISE_FUNCTION <nl> - <nl> - void THDTensor_ ( atan2 ) ( THDTensor * r_ , THDTensor * tx , THDTensor * ty ) { <nl> - THDTensor_ ( resizeAs ) ( r_ , tx ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorAtan2 , r_ , tx , ty ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( lerp ) ( THDTensor * r_ , THDTensor * a , THDTensor * b , real weight ) { <nl> - THArgCheck ( THDTensor_ ( nElement ) ( a ) = = THDTensor_ ( nElement ) ( b ) , 2 , <nl> - " sizes do not match " ) ; <nl> - THDTensor_ ( resizeAs ) ( r_ , a ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorLerp , r_ , a , b , weight ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( mean ) ( THDTensor * r_ , THDTensor * t , int dimension , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) , 2 , <nl> - " invalid dimension % d " , dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THLongStorage * dim = THDTensor_ ( newSizeOf ) ( t ) ; <nl> - THLongStorage_set ( dim , dimension , 1 ) ; <nl> - THDTensor_ ( resize ) ( r_ , dim , NULL ) ; <nl> - THLongStorage_free ( dim ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorMean , r_ , t , dimension , keepdim ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( ! keepdim ) { <nl> - THDTensor_ ( _squeeze1d ) ( r_ , r_ , dimension ) ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( std ) ( THDTensor * r_ , THDTensor * t , int dimension , int biased , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) , 3 , <nl> - " invalid dimension % d " , dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THLongStorage * dim = THDTensor_ ( newSizeOf ) ( t ) ; <nl> - THLongStorage_set ( dim , dimension , 1 ) ; <nl> - THDTensor_ ( resize ) ( r_ , dim , NULL ) ; <nl> - THLongStorage_free ( dim ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorStd , r_ , t , dimension , biased , keepdim ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( ! keepdim ) { <nl> - THDTensor_ ( _squeeze1d ) ( r_ , r_ , dimension ) ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( var ) ( THDTensor * r_ , THDTensor * t , int dimension , int biased , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) , 3 , <nl> - " invalid dimension % d " , dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THLongStorage * dim = THDTensor_ ( newSizeOf ) ( t ) ; <nl> - THLongStorage_set ( dim , dimension , 1 ) ; <nl> - THDTensor_ ( resize ) ( r_ , dim , NULL ) ; <nl> - THLongStorage_free ( dim ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorVar , r_ , t , dimension , biased , keepdim ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( ! keepdim ) { <nl> - THDTensor_ ( _squeeze1d ) ( r_ , r_ , dimension ) ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( norm ) ( THDTensor * r_ , THDTensor * t , real value , int dimension , int keepdim ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < THDTensor_ ( nDimensionLegacyNoScalars ) ( t ) , 3 , <nl> - " invalid dimension % d " , dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THLongStorage * dim = THDTensor_ ( newSizeOf ) ( t ) ; <nl> - THLongStorage_set ( dim , dimension , 1 ) ; <nl> - THDTensor_ ( resize ) ( r_ , dim , NULL ) ; <nl> - THLongStorage_free ( dim ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorNorm , r_ , t , dimension , keepdim , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( ! keepdim ) { <nl> - THDTensor_ ( _squeeze1d ) ( r_ , r_ , dimension ) ; <nl> - } <nl> - } <nl> - <nl> - accreal THDTensor_ ( normall ) ( THDTensor * tensor , real value ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorNormall , tensor , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < accreal > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( renorm ) ( THDTensor * res , THDTensor * src , real value , <nl> - int dimension , real maxnorm ) { <nl> - THArgCheck ( dimension > = 0 & & dimension < THDTensor_ ( nDimensionLegacyNoScalars ) ( src ) , 3 , <nl> - " invalid dimension % d " , dimension + TH_INDEX_BASE ) ; <nl> - THArgCheck ( value > 0 , 2 , " non - positive - norm not supported " ) ; <nl> - THArgCheck ( THDTensor_ ( nDimensionLegacyNoScalars ) ( src ) > 1 , 1 , <nl> - " need at least 2 dimensions , got % d dimensions " , <nl> - THDTensor_ ( nDimensionLegacyNoScalars ) ( src ) ) ; <nl> - <nl> - THDTensor_ ( resizeAs ) ( res , src ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorRenorm , res , src , dimension , value , maxnorm ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - accreal THDTensor_ ( dist ) ( THDTensor * tensor , THDTensor * src , real value ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorDist , tensor , src , value ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < accreal > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - accreal THDTensor_ ( meanall ) ( THDTensor * tensor ) { <nl> - THArgCheck ( tensor - > nDimension > 0 , 1 , " empty Tensor " ) ; <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorMeanall , tensor ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < accreal > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - accreal THDTensor_ ( varall ) ( THDTensor * tensor , int biased ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorVarall , tensor , biased ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < accreal > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - accreal THDTensor_ ( stdall ) ( THDTensor * tensor , int biased ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorStdall , tensor , biased ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < accreal > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( linspace ) ( THDTensor * r_ , real a , real b , int64_t n ) { <nl> - THArgCheck ( n > 1 | | ( n = = 1 & & ( a = = b ) ) , 3 , " invalid number of points " ) ; <nl> - <nl> - if ( THDTensor_ ( nElement ) ( r_ ) ! = n ) { <nl> - THDTensor_ ( resize1d ) ( r_ , n ) ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorLinspace , r_ , n , a , b ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( logspace ) ( THDTensor * r_ , real a , real b , int64_t n ) { <nl> - THArgCheck ( n > 1 | | ( n = = 1 & & ( a = = b ) ) , 3 , " invalid number of points " ) ; <nl> - <nl> - if ( THDTensor_ ( nElement ) ( r_ ) ! = n ) { <nl> - THDTensor_ ( resize1d ) ( r_ , n ) ; <nl> - } <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorLogspace , r_ , n , a , b ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( rand ) ( THDTensor * r_ , THDGenerator * _generator , <nl> - THLongStorage * size ) { <nl> - THDTensor_ ( resize ) ( r_ , size , NULL ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorRand , r_ , _generator , size ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( randn ) ( THDTensor * r_ , THDGenerator * _generator , <nl> - THLongStorage * size ) { <nl> - THDTensor_ ( resize ) ( r_ , size , NULL ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorRandn , r_ , _generator , size ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( histc ) ( THDTensor * hist , THDTensor * tensor , int64_t nbins , <nl> - real minvalue , real maxvalue ) { <nl> - THDTensor_ ( resize1d ) ( hist , nbins ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorHistc , hist , tensor , nbins , minvalue , maxvalue ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( bhistc ) ( THDTensor * hist , THDTensor * tensor , int64_t nbins , <nl> - real minvalue , real maxvalue ) { <nl> - THArgCheck ( THDTensor_ ( nDimensionLegacyNoScalars ) ( tensor ) < 3 , 2 , <nl> - " invalid dimension % d , the input must be a 2d tensor " , <nl> - THDTensor_ ( nDimensionLegacyNoScalars ) ( tensor ) ) ; <nl> - <nl> - int dimension = 1 ; <nl> - THArgCheck ( dimension > = 0 & & dimension < THDTensor_ ( nDimensionLegacyNoScalars ) ( tensor ) , 2 , <nl> - " invalid dimension % d " , dimension + TH_INDEX_BASE ) ; <nl> - <nl> - THDTensor_ ( resize2d ) ( hist , tensor - > size [ 0 ] , nbins ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorBhistc , hist , tensor , nbins , minvalue , maxvalue ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - # endif / / defined ( TH_REAL_IS_DOUBLE ) | | defined ( TH_REAL_IS_FLOAT ) <nl> - <nl> - # if defined ( TH_REAL_IS_BYTE ) <nl> - <nl> - int THDTensor_ ( logicalAnd ) ( THDTensor * tensor ) { <nl> - THArgCheck ( tensor - > nDimension > 0 , 1 , " empty Tensor " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorLogicalAnd , tensor ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < int > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - int THDTensor_ ( logicalAny ) ( THDTensor * tensor ) { <nl> - THArgCheck ( tensor - > nDimension > 0 , 1 , " empty Tensor " ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorLogicalAny , tensor ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - return receiveValueFromWorker < int > ( THDState : : s_current_worker ) ; <nl> - } <nl> - <nl> - # endif / / defined ( TH_REAL_IS_BYTE ) <nl> - <nl> - THD_API void THDTensor_ ( clshift ) ( THDTensor * r_ , THDTensor * t , THDTensor * src ) { <nl> - THError ( " clshift not implemented " ) ; <nl> - } <nl> - <nl> - THD_API void THDTensor_ ( crshift ) ( THDTensor * r_ , THDTensor * t , THDTensor * src ) { <nl> - THError ( " crshift not implemented " ) ; <nl> - } <nl> - <nl> - THD_API void THDTensor_ ( cbitand ) ( THDTensor * r_ , THDTensor * t , THDTensor * src ) { <nl> - THError ( " cbitand not implemented " ) ; <nl> - } <nl> - <nl> - THD_API void THDTensor_ ( cbitor ) ( THDTensor * r_ , THDTensor * t , THDTensor * src ) { <nl> - THError ( " cbitor not implemented " ) ; <nl> - } <nl> - <nl> - THD_API void THDTensor_ ( cbitxor ) ( THDTensor * r_ , THDTensor * t , THDTensor * src ) { <nl> - THError ( " cbitxor not implemented " ) ; <nl> - } <nl> - <nl> - THD_API void THDTensor_ ( lshift ) ( THDTensor * r_ , THDTensor * t , real value ) { <nl> - THError ( " lshift not implemented " ) ; <nl> - } <nl> - <nl> - THD_API void THDTensor_ ( rshift ) ( THDTensor * r_ , THDTensor * t , real value ) { <nl> - THError ( " rshift not implemented " ) ; <nl> - } <nl> - <nl> - THD_API void THDTensor_ ( bitand ) ( THDTensor * r_ , THDTensor * t , real value ) { <nl> - THError ( " bitand not implemented " ) ; <nl> - } <nl> - <nl> - THD_API void THDTensor_ ( bitor ) ( THDTensor * r_ , THDTensor * t , real value ) { <nl> - THError ( " bitor not implemented " ) ; <nl> - } <nl> - <nl> - THD_API void THDTensor_ ( bitxor ) ( THDTensor * r_ , THDTensor * t , real value ) { <nl> - THError ( " bitxor not implemented " ) ; <nl> - } <nl> - <nl> - # endif / / TH_GENERIC_FILE <nl> deleted file mode 100644 <nl> index 0a8d6b78902d . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensorMath . h <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensorMath . h " <nl> - # else <nl> - <nl> - THD_API void THDTensor_ ( gather ) ( THDTensor * self , THDTensor * src , int dim , <nl> - THDLongTensor * index ) ; <nl> - THD_API void THDTensor_ ( scatter ) ( THDTensor * self , int dim , THDLongTensor * index , <nl> - THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( scatterFill ) ( THDTensor * self , int dim , <nl> - THDLongTensor * index , real val ) ; <nl> - THD_API void THDTensor_ ( scatterAdd ) ( THDTensor * self , int dim , THDLongTensor * index , <nl> - THDTensor * src ) ; <nl> - <nl> - THD_API void THDTensor_ ( max ) ( THDTensor * self , THDLongTensor * indices_ , <nl> - THDTensor * src , int dimension , int keepdim ) ; <nl> - THD_API void THDTensor_ ( min ) ( THDTensor * self , THDLongTensor * indices_ , <nl> - THDTensor * src , int dimension , int keepdim ) ; <nl> - THD_API void THDTensor_ ( kthvalue ) ( THDTensor * self , THDLongTensor * indices_ , <nl> - THDTensor * src , int64_t k , int dimension , int keepdim ) ; <nl> - THD_API void THDTensor_ ( mode ) ( THDTensor * self , THDLongTensor * indices_ , <nl> - THDTensor * src , int dimension , int keepdim ) ; <nl> - THD_API void THDTensor_ ( median ) ( THDTensor * self , THDLongTensor * indices_ , <nl> - THDTensor * src , int dimension , int keepdim ) ; <nl> - <nl> - THD_API void THDTensor_ ( fill ) ( THDTensor * r_ , real value ) ; <nl> - THD_API void THDTensor_ ( zero ) ( THDTensor * r ) ; <nl> - THD_API void THDTensor_ ( maskedFill ) ( THDTensor * tensor , THDByteTensor * mask , real value ) ; <nl> - THD_API void THDTensor_ ( maskedCopy ) ( THDTensor * tensor , THDByteTensor * mask , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( maskedSelect ) ( THDTensor * tensor , THDTensor * src , THDByteTensor * mask ) ; <nl> - THD_API void THDTensor_ ( nonzero ) ( THDLongTensor * subscript , THDTensor * tensor ) ; <nl> - THD_API void THDTensor_ ( indexSelect ) ( THDTensor * tensor , THDTensor * src , int dim , <nl> - THDLongTensor * index ) ; <nl> - THD_API void THDTensor_ ( indexCopy ) ( THDTensor * tensor , int dim , THDLongTensor * index , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( indexAdd ) ( THDTensor * tensor , int dim , THDLongTensor * index , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( indexFill ) ( THDTensor * tensor , int dim , THDLongTensor * index , real val ) ; <nl> - <nl> - <nl> - THD_API void THDTensor_ ( zeros ) ( THDTensor * r_ , THLongStorage * size ) ; <nl> - THD_API void THDTensor_ ( ones ) ( THDTensor * r_ , THLongStorage * size ) ; <nl> - THD_API ptrdiff_t THDTensor_ ( numel ) ( THDTensor * t ) ; <nl> - <nl> - THD_API void THDTensor_ ( diag ) ( THDTensor * r_ , THDTensor * t , int k ) ; <nl> - THD_API void THDTensor_ ( eye ) ( THDTensor * r_ , int64_t n , int64_t m ) ; <nl> - THD_API void THDTensor_ ( range ) ( THDTensor * r_ , accreal xmin , accreal xmax , accreal step ) ; <nl> - THD_API void THDTensor_ ( randperm ) ( THDTensor * r_ , THDGenerator * _generator , int64_t n ) ; <nl> - THD_API void THDTensor_ ( reshape ) ( THDTensor * r_ , THDTensor * t , THDLongStorage * size ) ; <nl> - THD_API void THDTensor_ ( sort ) ( THDTensor * rt_ , THDLongTensor * ri_ , <nl> - THDTensor * t , int dimension , <nl> - int descendingOrder ) ; <nl> - THD_API void THDTensor_ ( topk ) ( THDTensor * rt_ , THDLongTensor * ri_ , <nl> - THDTensor * t , int64_t k , int dim , <nl> - int dir , int sorted ) ; <nl> - THD_API void THDTensor_ ( tril ) ( THDTensor * r_ , THDTensor * t , int64_t k ) ; <nl> - THD_API void THDTensor_ ( triu ) ( THDTensor * r_ , THDTensor * t , int64_t k ) ; <nl> - THD_API void THDTensor_ ( cat ) ( THDTensor * r_ , THDTensor * ta , <nl> - THDTensor * tb , int dimension ) ; <nl> - THD_API void THDTensor_ ( catArray ) ( THDTensor * result , THDTensor * * inputs , <nl> - int numInputs , int dimension ) ; <nl> - THD_API int THDTensor_ ( equal ) ( THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( ltValue ) ( THDByteTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( leValue ) ( THDByteTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( gtValue ) ( THDByteTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( geValue ) ( THDByteTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( neValue ) ( THDByteTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( eqValue ) ( THDByteTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( ltValueT ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( leValueT ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( gtValueT ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( geValueT ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( neValueT ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( eqValueT ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( ltTensor ) ( THDByteTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( leTensor ) ( THDByteTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( gtTensor ) ( THDByteTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( geTensor ) ( THDByteTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( neTensor ) ( THDByteTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( eqTensor ) ( THDByteTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( ltTensorT ) ( THDTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( leTensorT ) ( THDTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( gtTensorT ) ( THDTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( geTensorT ) ( THDTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( neTensorT ) ( THDTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( eqTensorT ) ( THDTensor * r_ , THDTensor * ta , THDTensor * tb ) ; <nl> - THD_API void THDTensor_ ( abs ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( sigmoid ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( log ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( log10 ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( log1p ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( log2 ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( exp ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( expm1 ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( cos ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( acos ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( cosh ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( sin ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( asin ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( sinh ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - <nl> - THD_API void THDTensor_ ( tan ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( atan ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( atan2 ) ( THDTensor * r_ , THDTensor * tx , THDTensor * ty ) ; <nl> - THD_API void THDTensor_ ( tanh ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( pow ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( tpow ) ( THDTensor * r_ , real value , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( sqrt ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( rsqrt ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( ceil ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( floor ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( round ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( abs ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( trunc ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( frac ) ( THDTensor * r_ , THDTensor * t ) ; <nl> - THD_API void THDTensor_ ( lerp ) ( THDTensor * r_ , THDTensor * a , THDTensor * b , real weight ) ; <nl> - THD_API void THDTensor_ ( mean ) ( THDTensor * r_ , THDTensor * t , int dimension , int keepdim ) ; <nl> - THD_API void THDTensor_ ( std ) ( THDTensor * r_ , THDTensor * t , int dimension , int biased , int keepdim ) ; <nl> - THD_API void THDTensor_ ( var ) ( THDTensor * r_ , THDTensor * t , int dimension , int biased , int keepdim ) ; <nl> - THD_API void THDTensor_ ( norm ) ( THDTensor * r_ , THDTensor * t , real value , <nl> - int dimension , int keepdim ) ; <nl> - THD_API void THDTensor_ ( renorm ) ( THDTensor * r_ , THDTensor * t , real value , <nl> - int dimension , real maxnorm ) ; <nl> - THD_API accreal THDTensor_ ( dist ) ( THDTensor * a , THDTensor * b , real value ) ; <nl> - THD_API void THDTensor_ ( histc ) ( THDTensor * hist , THDTensor * tensor , int64_t nbins , <nl> - real minvalue , real maxvalue ) ; <nl> - THD_API void THDTensor_ ( bhistc ) ( THDTensor * hist , THDTensor * tensor , int64_t nbins , <nl> - real minvalue , real maxvalue ) ; <nl> - THD_API accreal THDTensor_ ( meanall ) ( THDTensor * self ) ; <nl> - THD_API accreal THDTensor_ ( varall ) ( THDTensor * self , int biased ) ; <nl> - THD_API accreal THDTensor_ ( stdall ) ( THDTensor * self , int biased ) ; <nl> - THD_API accreal THDTensor_ ( normall ) ( THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( linspace ) ( THDTensor * r_ , real a , real b , int64_t n ) ; <nl> - THD_API void THDTensor_ ( logspace ) ( THDTensor * r_ , real a , real b , int64_t n ) ; <nl> - THD_API void THDTensor_ ( rand ) ( THDTensor * r_ , THDGenerator * _generator , <nl> - THLongStorage * size ) ; <nl> - THD_API void THDTensor_ ( randn ) ( THDTensor * r_ , THDGenerator * _generator , <nl> - THLongStorage * size ) ; <nl> - THD_API int THDTensor_ ( logicalAll ) ( THDTensor * self ) ; <nl> - THD_API int THDTensor_ ( logicalAny ) ( THDTensor * self ) ; <nl> - <nl> - THD_API void THDTensor_ ( clshift ) ( THDTensor * r_ , THDTensor * t , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( crshift ) ( THDTensor * r_ , THDTensor * t , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( cbitand ) ( THDTensor * r_ , THDTensor * t , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( cbitor ) ( THDTensor * r_ , THDTensor * t , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( cbitxor ) ( THDTensor * r_ , THDTensor * t , THDTensor * src ) ; <nl> - THD_API void THDTensor_ ( lshift ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( rshift ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( bitand ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( bitor ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - THD_API void THDTensor_ ( bitxor ) ( THDTensor * r_ , THDTensor * t , real value ) ; <nl> - <nl> - # endif <nl> deleted file mode 100644 <nl> index 05ec09748ce0 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensorMeta . cpp <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensorMeta . cpp " <nl> - # else <nl> - <nl> - using namespace thd ; <nl> - using namespace rpc ; <nl> - using namespace master ; <nl> - <nl> - / / taken from TH ( generic / THTensor . c ) <nl> - / / with a little fixes done so as to allocate <nl> - / / and free memory the way it is done in THDTensor <nl> - static void THDTensor_ ( _resize ) ( THDTensor * self , int nDimension , int64_t * size , int64_t * stride ) { <nl> - int nDimension_ ; <nl> - ptrdiff_t totalSize ; <nl> - bool hasRequiredSize = true ; <nl> - <nl> - nDimension_ = 0 ; <nl> - for ( size_t d = 0 ; d < nDimension ; d + + ) { <nl> - if ( size [ d ] > 0 ) { <nl> - nDimension_ + + ; <nl> - if ( ( self - > nDimension > d ) & & ( size [ d ] ! = self - > size [ d ] ) ) <nl> - hasRequiredSize = false ; <nl> - if ( ( self - > nDimension > d ) & & stride & & ( stride [ d ] > = 0 ) & & ( stride [ d ] ! = self - > stride [ d ] ) ) <nl> - hasRequiredSize = false ; <nl> - } else { <nl> - break ; <nl> - } <nl> - } <nl> - nDimension = nDimension_ ; <nl> - <nl> - if ( nDimension ! = self - > nDimension ) <nl> - hasRequiredSize = false ; <nl> - <nl> - if ( hasRequiredSize ) <nl> - return ; <nl> - <nl> - if ( nDimension > 0 ) { <nl> - if ( nDimension ! = self - > nDimension ) { <nl> - delete [ ] self - > size ; <nl> - delete [ ] self - > stride ; <nl> - self - > size = new int64_t [ nDimension ] ; <nl> - self - > stride = new int64_t [ nDimension ] ; <nl> - self - > nDimension = nDimension ; <nl> - } <nl> - <nl> - totalSize = 1 ; <nl> - for ( std : : ptrdiff_t d = self - > nDimension - 1 ; d > = 0 ; d - - ) { <nl> - self - > size [ d ] = size [ d ] ; <nl> - if ( stride & & ( stride [ d ] > = 0 ) ) { <nl> - self - > stride [ d ] = stride [ d ] ; <nl> - } else { <nl> - if ( d = = self - > nDimension - 1 ) <nl> - self - > stride [ d ] = 1 ; <nl> - else <nl> - self - > stride [ d ] = self - > size [ d + 1 ] * self - > stride [ d + 1 ] ; <nl> - } <nl> - totalSize + = ( self - > size [ d ] - 1 ) * self - > stride [ d ] ; <nl> - } <nl> - <nl> - if ( totalSize + self - > storageOffset > 0 ) { <nl> - if ( ! self - > storage ) <nl> - self - > storage = THDStorage_ ( new ) ( ) ; <nl> - if ( totalSize + self - > storageOffset > self - > storage - > size ) <nl> - THDStorage_ ( resize ) ( self - > storage , totalSize + self - > storageOffset ) ; <nl> - } <nl> - } else { <nl> - self - > nDimension = 0 ; <nl> - } <nl> - } <nl> - <nl> - void THDTensor_ ( _resize2d ) ( THDTensor * tensor , int64_t size0 , int64_t size1 ) { <nl> - int64_t sizes [ ] = { size0 , size1 } ; <nl> - THDTensor_ ( _resize ) ( tensor , 2 , sizes , nullptr ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( _resize3d ) ( THDTensor * tensor , int64_t size0 , int64_t size1 , int64_t size2 ) { <nl> - int64_t sizes [ ] = { size0 , size1 , size2 } ; <nl> - THDTensor_ ( _resize ) ( tensor , 2 , sizes , nullptr ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( _resize4d ) ( THDTensor * tensor , int64_t size0 , int64_t size1 , int64_t size2 , int64_t size3 ) { <nl> - int64_t sizes [ ] = { size0 , size1 , size2 , size3 } ; <nl> - THDTensor_ ( _resize ) ( tensor , 2 , sizes , nullptr ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( _resize5d ) ( THDTensor * tensor , int64_t size0 , int64_t size1 , int64_t size2 , int64_t size3 , int64_t size4 ) { <nl> - int64_t sizes [ ] = { size0 , size1 , size2 , size3 , size4 } ; <nl> - THDTensor_ ( _resize ) ( tensor , 2 , sizes , nullptr ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( _squeeze1d ) ( THDTensor * self , THDTensor * src , int dimension ) { <nl> - if ( ! src ) <nl> - src = self ; <nl> - <nl> - THArgCheck ( ( dimension > = 0 ) & & ( dimension < src - > nDimension ) , 2 , " dimension out of range " ) ; <nl> - <nl> - THDTensor_ ( set ) ( self , src ) ; <nl> - <nl> - if ( src - > size [ dimension ] = = 1 & & src - > nDimension > 1 ) { <nl> - for ( size_t d = dimension ; d < self - > nDimension - 1 ; d + + ) { <nl> - self - > size [ d ] = self - > size [ d + 1 ] ; <nl> - self - > stride [ d ] = self - > stride [ d + 1 ] ; <nl> - } <nl> - self - > nDimension - - ; <nl> - } <nl> - } <nl> - <nl> - static void THDTensor_ ( _set ) ( THDTensor * self , THDStorage * storage , <nl> - ptrdiff_t storageOffset , int nDimension , <nl> - int64_t * size , int64_t * stride ) { <nl> - / * storage * / <nl> - if ( self - > storage ! = storage ) { <nl> - if ( self - > storage ) <nl> - THDStorage_ ( free ) ( self - > storage ) ; <nl> - <nl> - if ( storage ) { <nl> - self - > storage = storage ; <nl> - THDStorage_ ( retain ) ( self - > storage ) ; <nl> - } else { <nl> - self - > storage = NULL ; <nl> - } <nl> - } <nl> - <nl> - / * storageOffset * / <nl> - if ( storageOffset < 0 ) <nl> - THError ( " can ' t set negative storage offset " ) ; <nl> - self - > storageOffset = storageOffset ; <nl> - <nl> - / * size and stride * / <nl> - THDTensor_ ( _resize ) ( self , nDimension , size , stride ) ; <nl> - } <nl> - <nl> - static THDTensor * THDTensor_ ( _alloc ) ( ) { <nl> - THDTensor * new_tensor = new THDTensor ( ) ; <nl> - std : : memset ( reinterpret_cast < void * > ( new_tensor ) , 0 , sizeof ( THDTensor ) ) ; <nl> - new_tensor - > size = nullptr ; <nl> - new_tensor - > stride = nullptr ; <nl> - new_tensor - > nDimension = 0 ; <nl> - <nl> - new_tensor - > storage = nullptr ; <nl> - new_tensor - > storageOffset = 0 ; <nl> - <nl> - new_tensor - > refcount = 1 ; <nl> - <nl> - new_tensor - > tensor_id = THDState : : s_nextId + + ; <nl> - return new_tensor ; <nl> - } <nl> - <nl> - # endif <nl> deleted file mode 100644 <nl> index 7b24d31b3f07 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensorRandom . cpp <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensorRandom . cpp " <nl> - # else <nl> - <nl> - using namespace thd ; <nl> - using namespace rpc ; <nl> - using namespace master ; <nl> - <nl> - void THDTensor_ ( random ) ( THDTensor * self , THDGenerator * _generator ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorRandom , self , _generator ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( geometric ) ( THDTensor * self , THDGenerator * _generator , double p ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorGeometric , self , _generator , p ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( bernoulli ) ( THDTensor * self , THDGenerator * _generator , double p ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorBernoulli , self , _generator , p ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( bernoulli_FloatTensor ) ( THDTensor * self , THDGenerator * _generator , <nl> - THDFloatTensor * p ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorBernoulli_FloatTensor , self , _generator , p ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( bernoulli_DoubleTensor ) ( THDTensor * self , THDGenerator * _generator , <nl> - THDDoubleTensor * p ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorBernoulli_DoubleTensor , self , _generator , p ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - # if defined ( TH_REAL_IS_FLOAT ) | | defined ( TH_REAL_IS_DOUBLE ) <nl> - <nl> - void THDTensor_ ( uniform ) ( THDTensor * self , THDGenerator * _generator , double a , <nl> - double b ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorUniform , self , _generator , a , b ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( normal ) ( THDTensor * self , THDGenerator * _generator , double mean , <nl> - double stdv ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorNormal , self , _generator , mean , stdv ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( exponential ) ( THDTensor * self , THDGenerator * _generator , <nl> - double lambda ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorExponential , self , _generator , lambda ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( cauchy ) ( THDTensor * self , THDGenerator * _generator , double median , <nl> - double sigma ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorCauchy , self , _generator , median , sigma ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( logNormal ) ( THDTensor * self , THDGenerator * _generator , double mean , <nl> - double stdv ) { <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( Functions : : tensorLogNormal , self , _generator , mean , stdv ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - } <nl> - <nl> - void THDTensor_ ( multinomial ) ( THDLongTensor * self , THDGenerator * _generator , <nl> - THDTensor * prob_dist , int n_sample , <nl> - int with_replacement ) { <nl> - int start_dim = THDTensor_ ( nDimensionLegacyNoScalars ) ( prob_dist ) ; <nl> - if ( start_dim = = 1 ) { <nl> - THDTensor_ ( resize2d ) ( prob_dist , 1 , THDTensor_ ( size ) ( prob_dist , 0 ) ) ; <nl> - } <nl> - <nl> - long n_dist = THDTensor_ ( size ) ( prob_dist , 0 ) ; <nl> - long n_categories = THDTensor_ ( size ) ( prob_dist , 1 ) ; <nl> - <nl> - THArgCheck ( n_sample > 0 , 2 , " cannot sample n_sample < 0 samples " ) ; <nl> - <nl> - if ( ! with_replacement ) { <nl> - THArgCheck ( ( ! with_replacement ) & & ( n_sample < = n_categories ) , 2 , \ <nl> - " cannot sample n_sample > prob_dist : size ( 1 ) samples without replacement " ) ; <nl> - } <nl> - <nl> - / * will contain multinomial samples ( category indices to be returned ) * / <nl> - THDLongTensor_resize2d ( self , n_dist , n_sample ) ; <nl> - <nl> - masterCommandChannel - > sendMessage ( <nl> - packMessage ( <nl> - Functions : : tensorMultinomial , <nl> - self , <nl> - _generator , <nl> - prob_dist , <nl> - n_sample , <nl> - with_replacement <nl> - ) , <nl> - THDState : : s_current_worker <nl> - ) ; <nl> - <nl> - if ( start_dim = = 1 ) { <nl> - THDLongTensor_resize1d ( self , n_sample ) ; <nl> - THDTensor_ ( resize1d ) ( prob_dist , n_categories ) ; <nl> - } <nl> - } <nl> - <nl> - # endif / / defined ( TH_REAL_IS_FLOAT ) | | defined ( TH_REAL_IS_DOUBLE ) <nl> - <nl> - # endif / / TH_GENERIC_FILE <nl> deleted file mode 100644 <nl> index 0857ebddaec6 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / master / generic / THDTensorRandom . h <nl> ppp / dev / null <nl> <nl> - # ifndef TH_GENERIC_FILE <nl> - # define TH_GENERIC_FILE " master_worker / master / generic / THDTensorRandom . h " <nl> - # else <nl> - <nl> - THD_API void THDTensor_ ( random ) ( THDTensor * self , THDGenerator * _generator ) ; <nl> - THD_API void THDTensor_ ( geometric ) ( THDTensor * self , THDGenerator * _generator , <nl> - double p ) ; <nl> - THD_API void THDTensor_ ( bernoulli ) ( THDTensor * self , THDGenerator * _generator , <nl> - double p ) ; <nl> - THD_API void THDTensor_ ( bernoulli_FloatTensor ) ( THDTensor * self , <nl> - THDGenerator * _generator , <nl> - THDFloatTensor * p ) ; <nl> - THD_API void THDTensor_ ( bernoulli_DoubleTensor ) ( THDTensor * self , <nl> - THDGenerator * _generator , <nl> - THDDoubleTensor * p ) ; <nl> - THD_API void THDTensor_ ( uniform ) ( THDTensor * self , THDGenerator * _generator , <nl> - double a , double b ) ; <nl> - THD_API void THDTensor_ ( normal ) ( THDTensor * self , THDGenerator * _generator , <nl> - double mean , double stdv ) ; <nl> - THD_API void THDTensor_ ( exponential ) ( THDTensor * self , THDGenerator * _generator , <nl> - double lambda ) ; <nl> - THD_API void THDTensor_ ( cauchy ) ( THDTensor * self , THDGenerator * _generator , <nl> - double median , double sigma ) ; <nl> - THD_API void THDTensor_ ( logNormal ) ( THDTensor * self , THDGenerator * _generator , <nl> - double mean , double stdv ) ; <nl> - THD_API void THDTensor_ ( multinomial ) ( THDLongTensor * self , <nl> - THDGenerator * _generator , <nl> - THDTensor * prob_dist , <nl> - int n_sample , <nl> - int with_replacement ) ; <nl> - <nl> - # endif <nl> deleted file mode 100644 <nl> index c0ba3cadabb4 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / Dispatch . cpp <nl> ppp / dev / null <nl> <nl> - # include < TH / THStorageFunctions . h > <nl> - # include < cstdint > <nl> - # include < unordered_map > <nl> - # include < memory > <nl> - # include < stdexcept > <nl> - # include < string > <nl> - # include < unordered_map > <nl> - <nl> - # include " . . / . . / process_group / General . hpp " <nl> - # include " . . / common / Functions . hpp " <nl> - # include " . . / common / RPC . hpp " <nl> - # include " . . / master / Master . hpp " <nl> - # include " Worker . hpp " <nl> - <nl> - namespace thd { <nl> - namespace worker { <nl> - <nl> - namespace detail { <nl> - <nl> - void sendValueToMaster ( int64_t value ) { <nl> - IntScalar scalar ( value ) ; <nl> - dataChannel - > send ( scalar , 0 ) ; <nl> - } <nl> - <nl> - void sendValueToMaster ( double value ) { <nl> - FloatScalar scalar ( value ) ; <nl> - dataChannel - > send ( scalar , 0 ) ; <nl> - } <nl> - <nl> - at : : Tensor & unpackRetrieveTensor ( rpc : : RPCMessage & message ) { <nl> - return workerTensors . at ( unpackTensor ( message ) ) ; <nl> - } <nl> - <nl> - at : : Storage & unpackRetrieveStorage ( rpc : : RPCMessage & message ) { <nl> - return workerStorages . at ( unpackStorage ( message ) ) ; <nl> - } <nl> - <nl> - at : : Generator * unpackRetrieveGenerator ( rpc : : RPCMessage & message ) { <nl> - return workerGenerators . at ( unpackGenerator ( message ) ) . get ( ) ; <nl> - } <nl> - <nl> - static void finalize ( rpc : : RPCMessage & raw_message ) { <nl> - if ( raw_message . remaining ( ) > 0 ) <nl> - throw std : : invalid_argument ( " message is too long " ) ; <nl> - } <nl> - <nl> - # include " dispatch / Communication . cpp " <nl> - # include " dispatch / Generator . cpp " <nl> - # include " dispatch / Storage . cpp " <nl> - # include " dispatch / Tensor . cpp " <nl> - # include " dispatch / TensorCopy . cpp " <nl> - # include " dispatch / TensorMath . cpp " <nl> - # include " dispatch / TensorRandom . cpp " <nl> - # include " dispatch / TensorLapack . cpp " <nl> - <nl> - using dispatch_fn = void ( * ) ( rpc : : RPCMessage & ) ; <nl> - using Functions = thd : : Functions ; <nl> - <nl> - void exitWorker ( rpc : : RPCMessage & msg ) { <nl> - finalize ( msg ) ; <nl> - : : exit ( 0 ) ; <nl> - } <nl> - <nl> - <nl> - static const std : : unordered_map < rpc : : function_id_type , dispatch_fn > functions { <nl> - { Functions : : generatorNew , generatorNew } , <nl> - { Functions : : generatorFree , generatorFree } , <nl> - { Functions : : generatorCopy , generatorCopy } , <nl> - { Functions : : generatorSeed , generatorSeed } , <nl> - { Functions : : generatorManualSeed , generatorManualSeed } , <nl> - <nl> - { Functions : : tensorCopyFromMaster , tensorCopyFromMaster } , <nl> - { Functions : : tensorCopyFromWorker , tensorCopyFromWorker } , <nl> - <nl> - { Functions : : tensorNew , tensorNew } , <nl> - { Functions : : tensorNewWithSize , tensorNewWithSize } , <nl> - { Functions : : tensorNewWithStorage , tensorNewWithStorage } , <nl> - { Functions : : tensorResize , tensorResize } , <nl> - { Functions : : tensorResizeAs , tensorResizeAs } , <nl> - { Functions : : tensorResize1d , tensorResize1d } , <nl> - { Functions : : tensorResize2d , tensorResize2d } , <nl> - { Functions : : tensorResize3d , tensorResize2d } , <nl> - { Functions : : tensorResize4d , tensorResize2d } , <nl> - { Functions : : tensorResize5d , tensorResize2d } , <nl> - { Functions : : tensorSetStorage , tensorSetStorage } , <nl> - { Functions : : tensorSetStorage1d , tensorSetStorage1d } , <nl> - { Functions : : tensorSetStorage2d , tensorSetStorage2d } , <nl> - { Functions : : tensorSetStorage3d , tensorSetStorage3d } , <nl> - { Functions : : tensorSetStorage4d , tensorSetStorage4d } , <nl> - { Functions : : tensorNarrow , tensorNarrow } , <nl> - { Functions : : tensorSelect , tensorSelect } , <nl> - { Functions : : tensorTranspose , tensorTranspose } , <nl> - { Functions : : tensorUnfold , tensorUnfold } , <nl> - { Functions : : tensorSqueeze , tensorSqueeze } , <nl> - { Functions : : tensorSqueeze , tensorSqueeze1d } , <nl> - <nl> - { Functions : : tensorFree , tensorFree } , <nl> - { Functions : : tensorAdd , tensorAdd } , <nl> - <nl> - { Functions : : tensorGather , tensorGather } , <nl> - { Functions : : tensorScatter , tensorScatter } , <nl> - { Functions : : tensorScatterFill , tensorScatterFill } , <nl> - { Functions : : tensorDot , tensorDot } , <nl> - { Functions : : tensorMinall , tensorMinall } , <nl> - { Functions : : tensorMaxall , tensorMaxall } , <nl> - { Functions : : tensorMedianall , tensorMedianall } , <nl> - { Functions : : tensorSumall , tensorSumall } , <nl> - { Functions : : tensorProdall , tensorProdall } , <nl> - { Functions : : tensorNeg , tensorNeg } , <nl> - { Functions : : tensorCinv , tensorCinv } , <nl> - { Functions : : tensorAdd , tensorAdd } , <nl> - { Functions : : tensorSub , tensorSub } , <nl> - { Functions : : tensorMul , tensorMul } , <nl> - { Functions : : tensorDiv , tensorDiv } , <nl> - { Functions : : tensorFmod , tensorFmod } , <nl> - { Functions : : tensorRemainder , tensorRemainder } , <nl> - { Functions : : tensorClamp , tensorClamp } , <nl> - { Functions : : tensorCadd , tensorCadd } , <nl> - { Functions : : tensorCsub , tensorCsub } , <nl> - { Functions : : tensorCmul , tensorCmul } , <nl> - { Functions : : tensorCpow , tensorCpow } , <nl> - { Functions : : tensorCdiv , tensorCdiv } , <nl> - { Functions : : tensorCfmod , tensorCfmod } , <nl> - { Functions : : tensorCremainder , tensorCremainder } , <nl> - { Functions : : tensorAddcmul , tensorAddcmul } , <nl> - { Functions : : tensorAddcdiv , tensorAddcdiv } , <nl> - { Functions : : tensorAddmv , tensorAddmv } , <nl> - { Functions : : tensorAddmm , tensorAddmm } , <nl> - { Functions : : tensorAddr , tensorAddr } , <nl> - { Functions : : tensorAddbmm , tensorAddbmm } , <nl> - { Functions : : tensorBaddbmm , tensorBaddbmm } , <nl> - / * { Functions : : tensorMatch , tensorMatch } , * / <nl> - { Functions : : tensorMax , tensorMax } , <nl> - { Functions : : tensorMin , tensorMin } , <nl> - { Functions : : tensorKthvalue , tensorKthvalue } , <nl> - { Functions : : tensorMode , tensorMode } , <nl> - { Functions : : tensorMedian , tensorMedian } , <nl> - { Functions : : tensorSum , tensorSum } , <nl> - { Functions : : tensorProd , tensorProd } , <nl> - { Functions : : tensorCumsum , tensorCumsum } , <nl> - { Functions : : tensorCumprod , tensorCumprod } , <nl> - { Functions : : tensorSign , tensorSign } , <nl> - { Functions : : tensorTrace , tensorTrace } , <nl> - { Functions : : tensorCross , tensorCross } , <nl> - { Functions : : tensorCmax , tensorCmax } , <nl> - { Functions : : tensorCmin , tensorCmin } , <nl> - / * { Functions : : tensorCmaxValue , tensorCmaxValue } , * / <nl> - / * { Functions : : tensorCminValue , tensorCminValue } , * / <nl> - <nl> - { Functions : : tensorFill , tensorFill } , <nl> - { Functions : : tensorMaskedFill , tensorMaskedFill } , <nl> - { Functions : : tensorMaskedCopy , tensorMaskedCopy } , <nl> - { Functions : : tensorMaskedSelect , tensorMaskedSelect } , <nl> - { Functions : : tensorNonzero , tensorNonzero } , <nl> - { Functions : : tensorIndexSelect , tensorIndexSelect } , <nl> - { Functions : : tensorIndexCopy , tensorIndexCopy } , <nl> - { Functions : : tensorIndexAdd , tensorIndexAdd } , <nl> - { Functions : : tensorIndexFill , tensorIndexFill } , <nl> - { Functions : : tensorDiag , tensorDiag } , <nl> - { Functions : : tensorEye , tensorEye } , <nl> - { Functions : : tensorRange , tensorRange } , <nl> - { Functions : : tensorRandperm , tensorRandperm } , <nl> - { Functions : : tensorSort , tensorSort } , <nl> - { Functions : : tensorTopk , tensorTopk } , <nl> - { Functions : : tensorTril , tensorTril } , <nl> - { Functions : : tensorTriu , tensorTriu } , <nl> - { Functions : : tensorEqual , tensorEqual } , <nl> - { Functions : : tensorLtValue , tensorLtValue } , <nl> - { Functions : : tensorLeValue , tensorLeValue } , <nl> - { Functions : : tensorGtValue , tensorGtValue } , <nl> - { Functions : : tensorGeValue , tensorGeValue } , <nl> - { Functions : : tensorNeValue , tensorNeValue } , <nl> - { Functions : : tensorEqValue , tensorEqValue } , <nl> - { Functions : : tensorLtValueT , tensorLtValueT } , <nl> - { Functions : : tensorLeValueT , tensorLeValueT } , <nl> - { Functions : : tensorGtValueT , tensorGtValueT } , <nl> - { Functions : : tensorGeValueT , tensorGeValueT } , <nl> - { Functions : : tensorNeValueT , tensorNeValueT } , <nl> - { Functions : : tensorEqValueT , tensorEqValueT } , <nl> - { Functions : : tensorLtTensor , tensorLtTensor } , <nl> - { Functions : : tensorLeTensor , tensorLeTensor } , <nl> - { Functions : : tensorGtTensor , tensorGtTensor } , <nl> - { Functions : : tensorGeTensor , tensorGeTensor } , <nl> - { Functions : : tensorNeTensor , tensorNeTensor } , <nl> - { Functions : : tensorEqTensor , tensorEqTensor } , <nl> - { Functions : : tensorLtTensorT , tensorLtTensorT } , <nl> - { Functions : : tensorLeTensorT , tensorLeTensorT } , <nl> - { Functions : : tensorGtTensorT , tensorGtTensorT } , <nl> - { Functions : : tensorGeTensorT , tensorGeTensorT } , <nl> - { Functions : : tensorNeTensorT , tensorNeTensorT } , <nl> - { Functions : : tensorEqTensorT , tensorEqTensorT } , <nl> - { Functions : : tensorAbs , tensorAbs } , <nl> - { Functions : : tensorSigmoid , tensorSigmoid } , <nl> - { Functions : : tensorLog , tensorLog } , <nl> - { Functions : : tensorLog10 , tensorLog10 } , <nl> - { Functions : : tensorLog1p , tensorLog1p } , <nl> - { Functions : : tensorLog2 , tensorLog2 } , <nl> - { Functions : : tensorExp , tensorExp } , <nl> - { Functions : : tensorExpm1 , tensorExpm1 } , <nl> - { Functions : : tensorCos , tensorCos } , <nl> - { Functions : : tensorAcos , tensorAcos } , <nl> - { Functions : : tensorCosh , tensorCosh } , <nl> - { Functions : : tensorSin , tensorSin } , <nl> - { Functions : : tensorAsin , tensorAsin } , <nl> - { Functions : : tensorSinh , tensorSinh } , <nl> - { Functions : : tensorTan , tensorTan } , <nl> - { Functions : : tensorAtan , tensorAtan } , <nl> - { Functions : : tensorAtan2 , tensorAtan2 } , <nl> - { Functions : : tensorTanh , tensorTanh } , <nl> - { Functions : : tensorPow , tensorPow } , <nl> - { Functions : : tensorTpow , tensorTpow } , <nl> - { Functions : : tensorSqrt , tensorSqrt } , <nl> - { Functions : : tensorRsqrt , tensorRsqrt } , <nl> - { Functions : : tensorCeil , tensorCeil } , <nl> - { Functions : : tensorFloor , tensorFloor } , <nl> - { Functions : : tensorRound , tensorRound } , <nl> - { Functions : : tensorTrunc , tensorTrunc } , <nl> - { Functions : : tensorFrac , tensorFrac } , <nl> - { Functions : : tensorLerp , tensorLerp } , <nl> - { Functions : : tensorMean , tensorMean } , <nl> - { Functions : : tensorStd , tensorStd } , <nl> - { Functions : : tensorVar , tensorVar } , <nl> - { Functions : : tensorNorm , tensorNorm } , <nl> - { Functions : : tensorRenorm , tensorRenorm } , <nl> - { Functions : : tensorDist , tensorDist } , <nl> - { Functions : : tensorHistc , tensorHistc } , <nl> - / * { Functions : : tensorBhistc , tensorBhistc } , * / <nl> - { Functions : : tensorMeanall , tensorMeanall } , <nl> - { Functions : : tensorVarall , tensorVarall } , <nl> - { Functions : : tensorStdall , tensorStdall } , <nl> - { Functions : : tensorNormall , tensorNormall } , <nl> - { Functions : : tensorLinspace , tensorLinspace } , <nl> - { Functions : : tensorLogspace , tensorLogspace } , <nl> - { Functions : : tensorRand , tensorRand } , <nl> - { Functions : : tensorRandn , tensorRandn } , <nl> - { Functions : : tensorLogicalAndAll , tensorLogicalAndAll } , <nl> - { Functions : : tensorLogicalAnd , tensorLogicalAnd } , <nl> - { Functions : : tensorLogicalAnyAll , tensorLogicalAnyAll } , <nl> - { Functions : : tensorLogicalAny , tensorLogicalAny } , <nl> - { Functions : : tensorRandom , tensorRandom } , <nl> - { Functions : : tensorGeometric , tensorGeometric } , <nl> - { Functions : : tensorBernoulli , tensorBernoulli } , <nl> - { Functions : : tensorBernoulli_FloatTensor , tensorBernoulli_FloatTensor } , <nl> - { Functions : : tensorBernoulli_DoubleTensor , tensorBernoulli_DoubleTensor } , <nl> - { Functions : : tensorUniform , tensorUniform } , <nl> - { Functions : : tensorNormal , tensorNormal } , <nl> - { Functions : : tensorExponential , tensorExponential } , <nl> - { Functions : : tensorCauchy , tensorCauchy } , <nl> - { Functions : : tensorLogNormal , tensorLogNormal } , <nl> - { Functions : : tensorMultinomial , tensorMultinomial } , <nl> - <nl> - { Functions : : tensorGesv , tensorGesv } , <nl> - { Functions : : tensorTrtrs , tensorTrtrs } , <nl> - { Functions : : tensorGels , tensorGels } , <nl> - { Functions : : tensorSyev , tensorSyev } , <nl> - { Functions : : tensorGeev , tensorGeev } , <nl> - { Functions : : tensorGesvd2 , tensorGesvd2 } , <nl> - { Functions : : tensorGetri , tensorGetri } , <nl> - { Functions : : tensorPotrf , tensorPotrf } , <nl> - { Functions : : tensorPotrs , tensorPotrs } , <nl> - { Functions : : tensorPotri , tensorPotri } , <nl> - { Functions : : tensorQr , tensorQr } , <nl> - { Functions : : tensorGeqrf , tensorGeqrf } , <nl> - { Functions : : tensorOrgqr , tensorOrgqr } , <nl> - { Functions : : tensorOrmqr , tensorOrmqr } , <nl> - { Functions : : tensorPstrf , tensorPstrf } , <nl> - <nl> - { Functions : : storageNew , storageNew } , <nl> - { Functions : : storageNewWithSize , storageNewWithSize } , <nl> - { Functions : : storageNewWithSize1 , storageNewWithSize1 } , <nl> - { Functions : : storageNewWithSize2 , storageNewWithSize2 } , <nl> - { Functions : : storageNewWithSize3 , storageNewWithSize3 } , <nl> - { Functions : : storageNewWithSize4 , storageNewWithSize4 } , <nl> - { Functions : : storageFree , storageFree } , <nl> - { Functions : : storageResize , storageResize } , <nl> - { Functions : : storageFill , storageFill } , <nl> - <nl> - { Functions : : sendTensor , sendTensor } , <nl> - { Functions : : sendStorage , sendStorage } , <nl> - <nl> - { Functions : : exit , exitWorker } <nl> - } ; <nl> - <nl> - } / / namespace detail <nl> - <nl> - / * On fail throws exceptions which should be caught in worker ' s loop and reported <nl> - * to master . <nl> - * / <nl> - void execute ( std : : unique_ptr < rpc : : RPCMessage > raw_message_ptr ) { <nl> - auto & raw_message = * raw_message_ptr ; <nl> - rpc : : function_id_type fid = rpc : : unpackFunctionId ( raw_message ) ; <nl> - auto iter = detail : : functions . find ( fid ) ; <nl> - if ( iter ! = detail : : functions . end ( ) ) { <nl> - ( * iter - > second ) ( raw_message ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " invalid function id : " + std : : to_string ( fid ) ) ; <nl> - } <nl> - } <nl> - <nl> - } / / namespace worker <nl> - } / / namespace thd <nl> deleted file mode 100644 <nl> index 7ec5941ba54d . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / Dispatch . hpp <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include " . . / common / RPC . hpp " <nl> - <nl> - # include < memory > <nl> - <nl> - namespace thd { <nl> - namespace worker { <nl> - <nl> - void execute ( std : : unique_ptr < rpc : : RPCMessage > raw_message_ptr ) ; <nl> - <nl> - } / / namespace worker <nl> - } / / namespace thd <nl> deleted file mode 100644 <nl> index 732e20391e96 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / Worker . cpp <nl> ppp / dev / null <nl> <nl> - # include " . . / . . / process_group / General . hpp " <nl> - # include " . . / common / RPC . hpp " <nl> - # include " Dispatch . hpp " <nl> - # include " Worker . h " <nl> - # include " Worker . hpp " <nl> - <nl> - # include < iostream > <nl> - # include < stdexcept > <nl> - <nl> - namespace thd { <nl> - namespace worker { <nl> - <nl> - std : : unique_ptr < WorkerCommandChannel > workerCommandChannel ; <nl> - std : : unordered_map < object_id_type , at : : Tensor > workerTensors ; <nl> - std : : unordered_map < object_id_type , at : : Storage > workerStorages ; <nl> - std : : unordered_map < object_id_type , std : : unique_ptr < at : : Generator > > workerGenerators ; <nl> - <nl> - } / / namespace worker <nl> - } / / namespace thd <nl> - <nl> - using namespace thd : : rpc ; <nl> - using namespace thd : : worker ; <nl> - <nl> - void THDWorkerMain ( std : : string init_method , int world_size , <nl> - std : : string group_name , int rank ) { <nl> - auto config = thd : : getInitConfig ( init_method , world_size , group_name , rank ) ; <nl> - std : : unique_ptr < RPCMessage > command ; <nl> - workerCommandChannel . reset ( new thd : : WorkerCommandChannel ( config ) ) ; <nl> - if ( ! workerCommandChannel - > init ( ) ) { <nl> - return ; <nl> - } <nl> - <nl> - while ( true ) { <nl> - command = workerCommandChannel - > recvMessage ( ) ; <nl> - try { <nl> - execute ( std : : move ( command ) ) ; <nl> - } catch ( std : : exception & e ) { <nl> - std : : cerr < < " WORKER ERROR : " < < e . what ( ) < < std : : endl ; <nl> - workerCommandChannel - > sendError ( e . what ( ) ) ; <nl> - : : exit ( 1 ) ; <nl> - } <nl> - } <nl> - } <nl> deleted file mode 100644 <nl> index 037decdae52e . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / Worker . h <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include " . . / . . / THD . h " <nl> - # include < string > <nl> - <nl> - THD_API void THDWorkerMain ( std : : string init_method , int world_size , <nl> - std : : string group_name , int rank ) ; <nl> deleted file mode 100644 <nl> index 5a65e0b0b4e1 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / Worker . hpp <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include " . . / common / CommandChannel . hpp " <nl> - # include " . . / . . / base / DataChannel . hpp " <nl> - <nl> - # include < memory > <nl> - <nl> - namespace thd { namespace worker { <nl> - extern std : : unique_ptr < WorkerCommandChannel > workerCommandChannel ; <nl> - extern std : : unordered_map < object_id_type , at : : Tensor > <nl> - workerTensors ; <nl> - extern std : : unordered_map < object_id_type , at : : Storage > <nl> - workerStorages ; <nl> - extern std : : unordered_map < object_id_type , std : : unique_ptr < at : : Generator > > <nl> - workerGenerators ; <nl> - } } / / namespace worker , thd <nl> deleted file mode 100644 <nl> index 547daae4aa97 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / dispatch / Communication . cpp <nl> ppp / dev / null <nl> <nl> - <nl> - static void sendTensor ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int dst_rank = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - dataChannel - > send ( tensor , dst_rank ) ; <nl> - } <nl> - <nl> - static void sendStorage ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Storage * storage = unpackRetrieveStorage ( raw_message ) ; <nl> - int dst_rank = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - fprintf ( stderr , " sending storage ( to be implemented ) \ n " ) ; <nl> - } <nl> deleted file mode 100644 <nl> index 884149fce378 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / dispatch / Generator . cpp <nl> ppp / dev / null <nl> <nl> - <nl> - static std : : unique_ptr < at : : Generator > createGenerator ( ) { <nl> - return std : : unique_ptr < at : : Generator > ( ) ; <nl> - } <nl> - <nl> - static void generatorNew ( rpc : : RPCMessage & raw_message ) { <nl> - object_id_type generator_id = unpackGenerator ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - workerGenerators . emplace ( generator_id , createGenerator ( ) ) ; <nl> - } <nl> - <nl> - static void generatorFree ( rpc : : RPCMessage & raw_message ) { <nl> - object_id_type generator_id = unpackGenerator ( raw_message ) ; <nl> - workerGenerators . erase ( generator_id ) ; <nl> - } <nl> - <nl> - static void generatorCopy ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Generator * self = unpackRetrieveGenerator ( raw_message ) ; <nl> - at : : Generator * from = unpackRetrieveGenerator ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - self - > copy ( * from ) ; <nl> - } <nl> - <nl> - static void generatorSeed ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - int64_t response = _generator - > seed ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } <nl> - <nl> - static void generatorManualSeed ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - uint64_t seed = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - _generator - > manualSeed ( seed ) ; <nl> - } <nl> deleted file mode 100644 <nl> index 7172cb11a11d . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / dispatch / Storage . cpp <nl> ppp / dev / null <nl> <nl> - static at : : Storage createStorage ( RPCType type ) { <nl> - if ( type = = RPCType : : UCHAR ) <nl> - return at : : getType ( at : : Backend : : CPU , at : : ScalarType : : Byte ) . storage ( ) ; <nl> - else if ( type = = RPCType : : CHAR ) <nl> - return at : : getType ( at : : Backend : : CPU , at : : ScalarType : : Char ) . storage ( ) ; <nl> - else if ( type = = RPCType : : SHORT ) <nl> - return at : : getType ( at : : Backend : : CPU , at : : ScalarType : : Short ) . storage ( ) ; <nl> - else if ( type = = RPCType : : INT ) <nl> - return at : : getType ( at : : Backend : : CPU , at : : ScalarType : : Int ) . storage ( ) ; <nl> - else if ( type = = RPCType : : LONG ) <nl> - return at : : getType ( at : : Backend : : CPU , at : : ScalarType : : Long ) . storage ( ) ; <nl> - else if ( type = = RPCType : : FLOAT ) <nl> - return at : : getType ( at : : Backend : : CPU , at : : ScalarType : : Float ) . storage ( ) ; <nl> - else if ( type = = RPCType : : DOUBLE ) <nl> - return at : : getType ( at : : Backend : : CPU , at : : ScalarType : : Double ) . storage ( ) ; <nl> - throw std : : invalid_argument ( " passed character doesn ' t represent a storage type " ) ; <nl> - } <nl> - <nl> - static at : : Storage createStorage ( RPCType type , size_t size ) { <nl> - at : : Storage storage = createStorage ( type ) ; <nl> - storage - > resize ( size ) ; <nl> - return storage ; <nl> - } <nl> - <nl> - static void storageSet ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Storage & storage = unpackRetrieveStorage ( raw_message ) ; <nl> - ptrdiff_t offset = unpackInteger ( raw_message ) ; <nl> - RPCType type = peekType ( raw_message ) ; <nl> - if ( isInteger ( type ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - storage - > set ( offset , value ) ; <nl> - } else if ( isFloat ( type ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - storage - > set ( offset , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void storageGet ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Storage & storage = unpackRetrieveStorage ( raw_message ) ; <nl> - ptrdiff_t offset = unpackInteger ( raw_message ) ; <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - if ( isInteger ( type ) ) { <nl> - int64_t value = storage - > get ( offset ) . to < int64_t > ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else if ( isFloat ( type ) ) { <nl> - double value = storage - > get ( offset ) . to < double > ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void storageNew ( rpc : : RPCMessage & raw_message ) { <nl> - RPCType storage_type = unpackType ( raw_message ) ; <nl> - object_id_type storage_id = unpackStorage ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - workerStorages . emplace ( <nl> - storage_id , <nl> - createStorage ( storage_type ) <nl> - ) ; <nl> - } <nl> - <nl> - static void storageNewWithSize ( rpc : : RPCMessage & raw_message ) { <nl> - RPCType storage_type = unpackType ( raw_message ) ; <nl> - object_id_type storage_id = unpackStorage ( raw_message ) ; <nl> - int64_t size = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - workerStorages . emplace ( <nl> - storage_id , <nl> - createStorage ( storage_type , size ) <nl> - ) ; <nl> - } <nl> - <nl> - static void storageNewWithSizeN ( rpc : : RPCMessage & raw_message , size_t size ) { <nl> - RPCType storage_type = unpackType ( raw_message ) ; <nl> - object_id_type storage_id = unpackStorage ( raw_message ) ; <nl> - at : : Storage storage = createStorage ( storage_type , size ) ; <nl> - RPCType value_type = peekType ( raw_message ) ; <nl> - if ( isInteger ( value_type ) ) { <nl> - int64_t values [ size ] ; <nl> - for ( size_t i = 0 ; i < size ; i + + ) <nl> - values [ i ] = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - for ( size_t i = 0 ; i < size ; i + + ) <nl> - storage - > fast_set ( i , values [ i ] ) ; <nl> - } else if ( isFloat ( value_type ) ) { <nl> - double values [ size ] ; <nl> - for ( size_t i = 0 ; i < size ; i + + ) <nl> - values [ i ] = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - for ( size_t i = 0 ; i < size ; i + + ) <nl> - storage - > fast_set ( i , values [ i ] ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - finalize ( raw_message ) ; <nl> - workerStorages . emplace ( <nl> - storage_id , <nl> - std : : move ( storage ) <nl> - ) ; <nl> - } <nl> - <nl> - static void storageNewWithSize1 ( rpc : : RPCMessage & raw_message ) { <nl> - storageNewWithSizeN ( raw_message , 1 ) ; <nl> - } <nl> - <nl> - static void storageNewWithSize2 ( rpc : : RPCMessage & raw_message ) { <nl> - storageNewWithSizeN ( raw_message , 2 ) ; <nl> - } <nl> - <nl> - static void storageNewWithSize3 ( rpc : : RPCMessage & raw_message ) { <nl> - storageNewWithSizeN ( raw_message , 3 ) ; <nl> - } <nl> - <nl> - static void storageNewWithSize4 ( rpc : : RPCMessage & raw_message ) { <nl> - storageNewWithSizeN ( raw_message , 4 ) ; <nl> - } <nl> - <nl> - static void storageFree ( rpc : : RPCMessage & raw_message ) { <nl> - object_id_type storage_id = unpackStorage ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - workerStorages . erase ( storage_id ) ; <nl> - } <nl> - <nl> - static void storageResize ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Storage & storage = unpackRetrieveStorage ( raw_message ) ; <nl> - int64_t new_size = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - storage - > resize ( new_size ) ; <nl> - } <nl> - <nl> - static void storageFill ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Storage * storage = unpackRetrieveStorage ( raw_message ) ; <nl> - RPCType type = peekType ( raw_message ) ; <nl> - if ( isInteger ( type ) ) { <nl> - int64_t val = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - storage - > fill ( val ) ; <nl> - } else if ( isFloat ( type ) ) { <nl> - double val = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - storage - > fill ( val ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> deleted file mode 100644 <nl> index 82f754ee9aa2 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / dispatch / Tensor . cpp <nl> ppp / dev / null <nl> <nl> - template < typename . . . Ts > <nl> - static at : : Tensor createTensor ( RPCType type , Ts & . . . args ) { <nl> - if ( type = = RPCType : : UCHAR ) <nl> - return at : : CPU ( at : : kByte ) . tensor ( std : : forward < Ts > ( args ) . . . ) ; <nl> - else if ( type = = RPCType : : CHAR ) <nl> - return at : : CPU ( at : : kChar ) . tensor ( std : : forward < Ts > ( args ) . . . ) ; <nl> - else if ( type = = RPCType : : SHORT ) <nl> - return at : : CPU ( at : : kShort ) . tensor ( std : : forward < Ts > ( args ) . . . ) ; <nl> - else if ( type = = RPCType : : INT ) <nl> - return at : : CPU ( at : : kInt ) . tensor ( std : : forward < Ts > ( args ) . . . ) ; <nl> - else if ( type = = RPCType : : LONG ) <nl> - return at : : CPU ( at : : kLong ) . tensor ( std : : forward < Ts > ( args ) . . . ) ; <nl> - else if ( type = = RPCType : : FLOAT ) <nl> - return at : : CPU ( at : : kFloat ) . tensor ( std : : forward < Ts > ( args ) . . . ) ; <nl> - else if ( type = = RPCType : : DOUBLE ) <nl> - return at : : CPU ( at : : kDouble ) . tensor ( std : : forward < Ts > ( args ) . . . ) ; <nl> - throw std : : invalid_argument ( " passed character doesn ' t represent a tensor type " ) ; <nl> - } <nl> - <nl> - static at : : Tensor createTensorWithStorage ( RPCType type , at : : Storage * storage , ptrdiff_t storageOffset , at : : IntList size , at : : IntList stride ) { <nl> - if ( type = = RPCType : : UCHAR ) <nl> - return at : : CPU ( at : : kByte ) . tensor ( * storage , storageOffset , size , stride ) ; <nl> - else if ( type = = RPCType : : CHAR ) <nl> - return at : : CPU ( at : : kChar ) . tensor ( * storage , storageOffset , size , stride ) ; <nl> - else if ( type = = RPCType : : SHORT ) <nl> - return at : : CPU ( at : : kShort ) . tensor ( * storage , storageOffset , size , stride ) ; <nl> - else if ( type = = RPCType : : INT ) <nl> - return at : : CPU ( at : : kInt ) . tensor ( * storage , storageOffset , size , stride ) ; <nl> - else if ( type = = RPCType : : LONG ) <nl> - return at : : CPU ( at : : kLong ) . tensor ( * storage , storageOffset , size , stride ) ; <nl> - else if ( type = = RPCType : : FLOAT ) <nl> - return at : : CPU ( at : : kFloat ) . tensor ( * storage , storageOffset , size , stride ) ; <nl> - else if ( type = = RPCType : : DOUBLE ) <nl> - return at : : CPU ( at : : kDouble ) . tensor ( * storage , storageOffset , size , stride ) ; <nl> - throw std : : invalid_argument ( " passed character doesn ' t represent a tensor type " ) ; <nl> - } <nl> - <nl> - static at : : Tensor createTensorWithTensor ( RPCType type , at : : Tensor & tensor ) { <nl> - if ( type = = RPCType : : UCHAR ) <nl> - return at : : CPU ( at : : kByte ) . alias ( tensor ) ; <nl> - else if ( type = = RPCType : : CHAR ) <nl> - return at : : CPU ( at : : kChar ) . alias ( tensor ) ; <nl> - else if ( type = = RPCType : : SHORT ) <nl> - return at : : CPU ( at : : kShort ) . alias ( tensor ) ; <nl> - else if ( type = = RPCType : : INT ) <nl> - return at : : CPU ( at : : kInt ) . alias ( tensor ) ; <nl> - else if ( type = = RPCType : : LONG ) <nl> - return at : : CPU ( at : : kLong ) . alias ( tensor ) ; <nl> - else if ( type = = RPCType : : FLOAT ) <nl> - return at : : CPU ( at : : kFloat ) . alias ( tensor ) ; <nl> - else if ( type = = RPCType : : DOUBLE ) <nl> - return at : : CPU ( at : : kDouble ) . alias ( tensor ) ; <nl> - throw std : : invalid_argument ( " passed character doesn ' t represent a tensor type " ) ; <nl> - } <nl> - <nl> - static void tensorNew ( rpc : : RPCMessage & raw_message ) { <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - thd : : object_id_type id = unpackTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - workerTensors . emplace ( <nl> - id , <nl> - createTensor ( type ) <nl> - ) ; <nl> - } <nl> - <nl> - static void tensorNewWithSize ( rpc : : RPCMessage & raw_message ) { <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - thd : : object_id_type id = unpackTensor ( raw_message ) ; <nl> - THLongStorage * size = unpackTHLongStorage ( raw_message ) ; <nl> - THLongStorage * stride = unpackTHLongStorage ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - at : : IntList sz ( THLongStorage_data ( size ) , THLongStorage_size ( size ) ) ; <nl> - at : : IntList str ( THLongStorage_data ( stride ) , THLongStorage_size ( stride ) ) ; <nl> - workerTensors . emplace ( <nl> - id , <nl> - createTensor ( type , sz , str ) <nl> - ) ; <nl> - THLongStorage_free ( size ) ; <nl> - THLongStorage_free ( stride ) ; <nl> - } <nl> - <nl> - static void tensorNewWithStorage ( rpc : : RPCMessage & raw_message ) { <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - thd : : object_id_type id = unpackTensor ( raw_message ) ; <nl> - at : : Storage * storage = unpackRetrieveStorage ( raw_message ) ; <nl> - ptrdiff_t storageOffset = unpackInteger ( raw_message ) ; <nl> - THLongStorage * size = unpackTHLongStorage ( raw_message ) ; <nl> - THLongStorage * stride = unpackTHLongStorage ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - at : : IntList sz ( THLongStorage_data ( size ) , THLongStorage_size ( size ) ) ; <nl> - at : : IntList str ( THLongStorage_data ( stride ) , THLongStorage_size ( stride ) ) ; <nl> - workerTensors . emplace ( <nl> - id , <nl> - createTensorWithStorage ( type , storage , storageOffset , sz , str ) <nl> - ) ; <nl> - THLongStorage_free ( size ) ; <nl> - THLongStorage_free ( stride ) ; <nl> - } <nl> - <nl> - static void tensorNewWithTensor ( rpc : : RPCMessage & raw_message ) { <nl> - RPCType type = unpackType ( raw_message ) ; <nl> - thd : : object_id_type id = unpackTensor ( raw_message ) ; <nl> - at : : Tensor self = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - workerTensors . emplace ( <nl> - id , <nl> - createTensorWithTensor ( type , self ) <nl> - ) ; <nl> - } <nl> - <nl> - static void tensorNewClone ( rpc : : RPCMessage & raw_message ) { <nl> - thd : : object_id_type id = unpackTensor ( raw_message ) ; <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - workerTensors . emplace ( <nl> - id , <nl> - tensor . clone ( ) <nl> - ) ; <nl> - } <nl> - <nl> - static void tensorResize ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - THLongStorage * size = unpackTHLongStorage ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : ArrayRef < int64_t > sizeRef ( THLongStorage_data ( size ) , THLongStorage_size ( size ) ) ; <nl> - tensor . resize_ ( sizeRef ) ; <nl> - THLongStorage_free ( size ) ; <nl> - } <nl> - <nl> - static void tensorResizeAs ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . resize_as_ ( src ) ; <nl> - } <nl> - <nl> - static void tensorResizeNd ( rpc : : RPCMessage & raw_message , size_t N ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - std : : vector < int64_t > size ( N ) ; <nl> - for ( size_t i = 0 ; i < N ; + + i ) { <nl> - size [ i ] = unpackInteger ( raw_message ) ; <nl> - } <nl> - finalize ( raw_message ) ; <nl> - tensor . resize_ ( size ) ; <nl> - } <nl> - <nl> - static void tensorResize1d ( rpc : : RPCMessage & raw_message ) { <nl> - tensorResizeNd ( raw_message , 1 ) ; <nl> - } <nl> - <nl> - static void tensorResize2d ( rpc : : RPCMessage & raw_message ) { <nl> - tensorResizeNd ( raw_message , 2 ) ; <nl> - } <nl> - <nl> - static void tensorResize3d ( rpc : : RPCMessage & raw_message ) { <nl> - tensorResizeNd ( raw_message , 3 ) ; <nl> - } <nl> - <nl> - static void tensorResize4d ( rpc : : RPCMessage & raw_message ) { <nl> - tensorResizeNd ( raw_message , 4 ) ; <nl> - } <nl> - <nl> - static void tensorResize5d ( rpc : : RPCMessage & raw_message ) { <nl> - tensorResizeNd ( raw_message , 5 ) ; <nl> - } <nl> - <nl> - static void tensorSet ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . set_ ( src ) ; <nl> - } <nl> - <nl> - static void tensorSetStorage ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Storage * storage = unpackRetrieveStorage ( raw_message ) ; <nl> - ptrdiff_t storageOffset = unpackInteger ( raw_message ) ; <nl> - THLongStorage * size = unpackTHLongStorage ( raw_message ) ; <nl> - THLongStorage * stride = unpackTHLongStorage ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : ArrayRef < int64_t > sizeRef ( THLongStorage_data ( size ) , THLongStorage_size ( size ) ) ; <nl> - at : : ArrayRef < int64_t > strideRef ( THLongStorage_data ( stride ) , THLongStorage_size ( stride ) ) ; <nl> - tensor . set_ ( <nl> - * storage , <nl> - storageOffset , <nl> - sizeRef , <nl> - strideRef <nl> - ) ; <nl> - THLongStorage_free ( size ) ; <nl> - THLongStorage_free ( stride ) ; <nl> - } <nl> - <nl> - static void tensorSetStorage1d ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Storage * storage = unpackRetrieveStorage ( raw_message ) ; <nl> - ptrdiff_t storageOffset = unpackInteger ( raw_message ) ; <nl> - int64_t size0 = unpackInteger ( raw_message ) ; <nl> - int64_t stride0 = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : ArrayRef < int64_t > sizes ( size0 ) ; <nl> - at : : ArrayRef < int64_t > strides ( stride0 ) ; <nl> - tensor . set_ ( <nl> - * storage , <nl> - storageOffset , <nl> - sizes , <nl> - strides <nl> - ) ; <nl> - } <nl> - <nl> - static void tensorSetStorage2d ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Storage * storage = unpackRetrieveStorage ( raw_message ) ; <nl> - ptrdiff_t storageOffset = unpackInteger ( raw_message ) ; <nl> - int64_t size0 = unpackInteger ( raw_message ) ; <nl> - int64_t stride0 = unpackInteger ( raw_message ) ; <nl> - int64_t size1 = unpackInteger ( raw_message ) ; <nl> - int64_t stride1 = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - THLongStorage * sizes = THLongStorage_newWithSize2 ( size0 , size1 ) ; <nl> - THLongStorage * strides = THLongStorage_newWithSize2 ( stride0 , stride1 ) ; <nl> - at : : ArrayRef < int64_t > sizeRef ( THLongStorage_data ( sizes ) , THLongStorage_size ( sizes ) ) ; <nl> - at : : ArrayRef < int64_t > strideRef ( THLongStorage_data ( strides ) , THLongStorage_size ( strides ) ) ; <nl> - tensor . set_ ( <nl> - * storage , <nl> - storageOffset , <nl> - sizeRef , <nl> - strideRef <nl> - ) ; <nl> - THLongStorage_free ( sizes ) ; <nl> - THLongStorage_free ( strides ) ; <nl> - } <nl> - <nl> - static void tensorSetStorage3d ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Storage * storage = unpackRetrieveStorage ( raw_message ) ; <nl> - ptrdiff_t storageOffset = unpackInteger ( raw_message ) ; <nl> - int64_t size0 = unpackInteger ( raw_message ) ; <nl> - int64_t stride0 = unpackInteger ( raw_message ) ; <nl> - int64_t size1 = unpackInteger ( raw_message ) ; <nl> - int64_t stride1 = unpackInteger ( raw_message ) ; <nl> - int64_t size2 = unpackInteger ( raw_message ) ; <nl> - int64_t stride2 = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - THLongStorage * sizes = THLongStorage_newWithSize3 ( size0 , size1 , size2 ) ; <nl> - THLongStorage * strides = THLongStorage_newWithSize3 ( stride0 , stride1 , stride2 ) ; <nl> - at : : ArrayRef < int64_t > sizeRef ( THLongStorage_data ( sizes ) , THLongStorage_size ( sizes ) ) ; <nl> - at : : ArrayRef < int64_t > strideRef ( THLongStorage_data ( strides ) , THLongStorage_size ( strides ) ) ; <nl> - tensor . set_ ( <nl> - * storage , <nl> - storageOffset , <nl> - sizeRef , <nl> - strideRef <nl> - ) ; <nl> - THLongStorage_free ( sizes ) ; <nl> - THLongStorage_free ( strides ) ; <nl> - } <nl> - <nl> - static void tensorSetStorage4d ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Storage * storage = unpackRetrieveStorage ( raw_message ) ; <nl> - ptrdiff_t storageOffset = unpackInteger ( raw_message ) ; <nl> - int64_t size0 = unpackInteger ( raw_message ) ; <nl> - int64_t stride0 = unpackInteger ( raw_message ) ; <nl> - int64_t size1 = unpackInteger ( raw_message ) ; <nl> - int64_t stride1 = unpackInteger ( raw_message ) ; <nl> - int64_t size2 = unpackInteger ( raw_message ) ; <nl> - int64_t stride2 = unpackInteger ( raw_message ) ; <nl> - int64_t size3 = unpackInteger ( raw_message ) ; <nl> - int64_t stride3 = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - THLongStorage * sizes = THLongStorage_newWithSize4 ( size0 , size1 , size2 , size3 ) ; <nl> - THLongStorage * strides = THLongStorage_newWithSize4 ( stride0 , stride1 , <nl> - stride2 , stride3 ) ; <nl> - at : : ArrayRef < int64_t > sizeRef ( THLongStorage_data ( sizes ) , THLongStorage_size ( sizes ) ) ; <nl> - at : : ArrayRef < int64_t > strideRef ( THLongStorage_data ( strides ) , THLongStorage_size ( strides ) ) ; <nl> - tensor . set_ ( <nl> - * storage , <nl> - storageOffset , <nl> - sizeRef , <nl> - strideRef <nl> - ) ; <nl> - THLongStorage_free ( sizes ) ; <nl> - THLongStorage_free ( strides ) ; <nl> - } <nl> - <nl> - static void tensorNarrow ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int64_t firstIndex = unpackInteger ( raw_message ) ; <nl> - int64_t size = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor = src . narrow ( dimension , firstIndex , size ) ; <nl> - } <nl> - <nl> - static void tensorSelect ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int64_t sliceIndex = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor = src . select ( dimension , sliceIndex ) ; <nl> - } <nl> - <nl> - static void tensorTranspose ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension1 = unpackInteger ( raw_message ) ; <nl> - int dimension2 = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor = src . transpose ( dimension1 , dimension2 ) ; <nl> - } <nl> - <nl> - static void tensorUnfold ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int64_t size = unpackInteger ( raw_message ) ; <nl> - int64_t step = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor = src . unfold ( dimension , size , step ) ; <nl> - } <nl> - <nl> - static void tensorSqueeze ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - / / FIXME : could be at : : squeeze_out ( tensor , src ) , but we don ' t generate <nl> - / / _out functions for native ATen functions ( and may not want to ) . <nl> - tensor . set_ ( src . squeeze ( ) ) ; <nl> - } <nl> - <nl> - static void tensorSqueeze1d ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - / / FIXME : could be at : : squeeze_out ( tensor , src , dimension ) , but we don ' t generate <nl> - / / _out functions for native ATen functions ( and may not want to ) . <nl> - tensor . set_ ( src . squeeze ( dimension ) ) ; <nl> - } <nl> - <nl> - static void tensorFree ( rpc : : RPCMessage & raw_message ) { <nl> - object_id_type tensor_id = unpackTensor ( raw_message ) ; <nl> - ( void ) workerTensors . erase ( tensor_id ) ; <nl> - } <nl> - <nl> - static void tensorGather ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dim = unpackInteger ( raw_message ) ; <nl> - at : : Tensor index = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : gather_out ( tensor , src , dim , index ) ; <nl> - } <nl> - <nl> - static void tensorScatter ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int dim = unpackInteger ( raw_message ) ; <nl> - at : : Tensor index = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . scatter_ ( dim , index , src ) ; <nl> - } <nl> - <nl> - static void tensorScatterFill ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int dim = unpackInteger ( raw_message ) ; <nl> - at : : Tensor index = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . scatter_ ( dim , index , value ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . scatter_ ( dim , index , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorDot ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = tensor . dot ( src ) . toCLong ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = tensor . dot ( src ) . toCDouble ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorMinall ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = tensor . min ( ) . toCLong ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = tensor . min ( ) . toCDouble ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorMaxall ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = tensor . max ( ) . toCLong ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = tensor . max ( ) . toCDouble ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorMedianall ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = tensor . median ( ) . toCLong ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = tensor . median ( ) . toCDouble ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorSumall ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = tensor . sum ( ) . toCLong ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = tensor . sum ( ) . toCDouble ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorProdall ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = tensor . prod ( ) . toCLong ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = tensor . prod ( ) . toCDouble ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorAdd ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : add_out ( tensor , src , at : : Scalar ( value ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : add_out ( tensor , src , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorSub ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : sub_out ( tensor , src , at : : Scalar ( ( int64_t ) value ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : sub_out ( tensor , src , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorMul ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : mul_out ( tensor , src , at : : Scalar ( ( int64_t ) value ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : mul_out ( tensor , src , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorDiv ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : div_out ( tensor , src , at : : Scalar ( ( int64_t ) value ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : div_out ( tensor , src , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorFmod ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : fmod_out ( tensor , src , at : : Scalar ( ( int64_t ) value ) ) ; <nl> - } else { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : fmod_out ( tensor , src , value ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorRemainder ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : remainder_out ( tensor , src , at : : Scalar ( ( int64_t ) value ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : remainder_out ( tensor , src , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorClamp ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t min_value = unpackInteger ( raw_message ) ; <nl> - int64_t max_value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : clamp_out ( tensor , src , at : : Scalar ( ( int64_t ) min_value ) , at : : Scalar ( ( int64_t ) max_value ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double min_value = unpackFloat ( raw_message ) ; <nl> - double max_value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : clamp_out ( tensor , src , min_value , max_value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorCadd ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : add_out ( tensor , src1 , src2 , at : : Scalar ( ( int64_t ) value ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : add_out ( tensor , src1 , src2 , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorCsub ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : sub_out ( tensor , src1 , src2 , at : : Scalar ( ( int64_t ) value ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : sub_out ( tensor , src1 , src2 , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorCmul ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : mul_out ( tensor , src1 , src2 ) ; <nl> - } <nl> - <nl> - static void tensorCpow ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : pow_out ( tensor , src1 , src2 ) ; <nl> - } <nl> - <nl> - static void tensorCdiv ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : div_out ( tensor , src1 , src2 ) ; <nl> - } <nl> - <nl> - static void tensorCfmod ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : fmod_out ( tensor , src1 , src2 ) ; <nl> - } <nl> - <nl> - static void tensorCremainder ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : remainder_out ( tensor , src1 , src2 ) ; <nl> - } <nl> - <nl> - static void tensorAddcmul ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src3 = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addcmul_out ( tensor , src1 , src2 , src3 , at : : Scalar ( ( int64_t ) value ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addcmul_out ( tensor , src1 , src2 , src3 , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorAddcdiv ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src3 = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addcdiv_out ( tensor , src1 , src2 , src3 , at : : Scalar ( ( int64_t ) value ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addcdiv_out ( tensor , src1 , src2 , src3 , value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorAddmv ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor mat = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor vec = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t beta = unpackInteger ( raw_message ) ; <nl> - int64_t alpha = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addmv_out ( tensor , src , mat , vec , at : : Scalar ( ( int64_t ) beta ) , at : : Scalar ( ( int64_t ) alpha ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double beta = unpackFloat ( raw_message ) ; <nl> - double alpha = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addmv_out ( tensor , src , mat , vec , beta , alpha ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorAddmm ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor mat1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor mat2 = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t beta = unpackInteger ( raw_message ) ; <nl> - int64_t alpha = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addmm_out ( tensor , src , mat1 , mat2 , at : : Scalar ( ( int64_t ) beta ) , at : : Scalar ( ( int64_t ) alpha ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double beta = unpackFloat ( raw_message ) ; <nl> - double alpha = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addmm_out ( tensor , src , mat1 , mat2 , beta , alpha ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorAddr ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor vec1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor vec2 = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t beta = unpackInteger ( raw_message ) ; <nl> - int64_t alpha = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addr_out ( tensor , src , vec1 , vec2 , at : : Scalar ( ( int64_t ) beta ) , at : : Scalar ( ( int64_t ) alpha ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double beta = unpackFloat ( raw_message ) ; <nl> - double alpha = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addr_out ( tensor , src , vec1 , vec2 , beta , alpha ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorAddbmm ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor batch1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor batch2 = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t beta = unpackInteger ( raw_message ) ; <nl> - int64_t alpha = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addbmm_out ( tensor , src , batch1 , batch2 , at : : Scalar ( ( int64_t ) beta ) , at : : Scalar ( ( int64_t ) alpha ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double beta = unpackFloat ( raw_message ) ; <nl> - double alpha = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : addbmm_out ( tensor , src , batch1 , batch2 , beta , alpha ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorBaddbmm ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor batch1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor batch2 = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t beta = unpackInteger ( raw_message ) ; <nl> - int64_t alpha = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : baddbmm_out ( tensor , src , batch1 , batch2 , at : : Scalar ( ( int64_t ) beta ) , at : : Scalar ( ( int64_t ) alpha ) ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double beta = unpackFloat ( raw_message ) ; <nl> - double alpha = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : baddbmm_out ( tensor , src , batch1 , batch2 , beta , alpha ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorMax ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor indices_ = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : max_out ( tensor , indices_ , src , dimension , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorMin ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor indices_ = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : min_out ( tensor , indices_ , src , dimension , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorKthvalue ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor indices_ = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int k = unpackInteger ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : kthvalue_out ( tensor , indices_ , src , k , dimension , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorMode ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor indices_ = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : mode_out ( tensor , indices_ , src , dimension , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorMedian ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor indices_ = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : median_out ( tensor , indices_ , src , dimension , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorSum ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : sum_out ( tensor , src , dimension , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorProd ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : prod_out ( tensor , src , dimension , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorCumsum ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : cumsum_out ( tensor , src , dimension ) ; <nl> - } <nl> - <nl> - static void tensorCumprod ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : cumprod_out ( tensor , src , dimension ) ; <nl> - } <nl> - <nl> - static void tensorSign ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : sign_out ( tensor , src ) ; <nl> - } <nl> - <nl> - static void tensorTrace ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = tensor . trace ( ) . toCLong ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = tensor . trace ( ) . toCDouble ( ) ; <nl> - sendValueToMaster ( value ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorCross ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : cross_out ( tensor , src1 , src2 , dimension ) ; <nl> - } <nl> - <nl> - static void tensorCmax ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : max_out ( tensor , src1 , src2 ) ; <nl> - } <nl> - <nl> - static void tensorCmin ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src1 = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src2 = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : min_out ( tensor , src1 , src2 ) ; <nl> - } <nl> - <nl> - / * static void tensorCmaxValue ( rpc : : RPCMessage & raw_message ) { * / <nl> - / * at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; * / <nl> - / * at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; * / <nl> - <nl> - / * if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { * / <nl> - / * int64_t value = unpackInteger ( raw_message ) ; * / <nl> - / * finalize ( raw_message ) ; * / <nl> - / * at : : clamp_out ( tensor , src , at : : Scalar ( ( int64_t ) value ) ) ; * / <nl> - / * } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { * / <nl> - / * double value = unpackFloat ( raw_message ) ; * / <nl> - / * finalize ( raw_message ) ; * / <nl> - / * at : : clamp_out ( tensor , src , value ) ; * / <nl> - / * } else { * / <nl> - / * throw std : : invalid_argument ( " expected scalar type " ) ; * / <nl> - / * } * / <nl> - / * } * / <nl> - <nl> - / * static void tensorCminValue ( rpc : : RPCMessage & raw_message ) { * / <nl> - / * at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; * / <nl> - / * at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; * / <nl> - <nl> - / * if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { * / <nl> - / * int64_t value = unpackInteger ( raw_message ) ; * / <nl> - / * finalize ( raw_message ) ; * / <nl> - / * dynamic_cast < thpp : : IntTensor * > ( tensor ) - > cminValue ( * src , value ) ; * / <nl> - / * } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { * / <nl> - / * double value = unpackFloat ( raw_message ) ; * / <nl> - / * finalize ( raw_message ) ; * / <nl> - / * dynamic_cast < thpp : : FloatTensor * > ( tensor ) - > cminValue ( * src , value ) ; * / <nl> - / * } else { * / <nl> - / * throw std : : invalid_argument ( " expected scalar type " ) ; * / <nl> - / * } * / <nl> - / * } * / <nl> deleted file mode 100644 <nl> index 2217900aeea6 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / dispatch / TensorCopy . cpp <nl> ppp / dev / null <nl> <nl> - <nl> - static void tensorCopyFromMaster ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor data = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - dataChannel - > receive ( data , 0 ) ; <nl> - } <nl> - <nl> - static void tensorCopyFromWorker ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor data = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - dataChannel - > send ( data , 0 ) ; <nl> - } <nl> deleted file mode 100644 <nl> index 10e79077c5fe . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / dispatch / TensorLapack . cpp <nl> ppp / dev / null <nl> <nl> - <nl> - static void tensorGesv ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor rb = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor b = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : gesv_out ( rb , ra , b , a ) ; <nl> - } <nl> - <nl> - static void tensorTrtrs ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor rb = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor b = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - auto uplo = unpackInteger ( raw_message ) ; <nl> - auto trans = unpackInteger ( raw_message ) ; <nl> - auto diag = unpackInteger ( raw_message ) ; <nl> - at : : trtrs_out ( rb , ra , b , a , uplo , trans , diag ) ; <nl> - } <nl> - <nl> - static void tensorGels ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor rb = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor b = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : gels_out ( rb , ra , b , a ) ; <nl> - } <nl> - <nl> - static void tensorSyev ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor re = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor rv = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - auto jobz = unpackInteger ( raw_message ) ; <nl> - auto uplo = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : symeig_out ( re , rv , a , jobz , uplo ) ; <nl> - } <nl> - <nl> - static void tensorGeev ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor re = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor rv = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - auto jobvr = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : eig_out ( re , rv , a , jobvr ) ; <nl> - } <nl> - <nl> - static void tensorGesvd2 ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor ru = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor rs = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor rv = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - auto jobu = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - throw std : : runtime_error ( " gesv2d not implemented in ATen " ) ; <nl> - / * ru - > gesvd2 ( * rs , * rv , * ra , * a , & jobu ) ; * / <nl> - } <nl> - <nl> - static void tensorGetri ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : inverse_out ( ra , a ) ; <nl> - } <nl> - <nl> - static void tensorPotrf ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - auto uplo = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : potrf_out ( ra , a , uplo ) ; <nl> - } <nl> - <nl> - static void tensorPotrs ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor rb = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor b = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - auto uplo = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : potrs_out ( rb , b , a , uplo ) ; <nl> - } <nl> - <nl> - static void tensorPotri ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - auto uplo = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : potri_out ( ra , a , uplo ) ; <nl> - } <nl> - <nl> - static void tensorQr ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor rq = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor rr = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : qr_out ( rq , rr , a ) ; <nl> - } <nl> - <nl> - static void tensorGeqrf ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor rtau = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : geqrf_out ( ra , rtau , a ) ; <nl> - } <nl> - <nl> - static void tensorOrgqr ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor tau = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : orgqr_out ( ra , a , tau ) ; <nl> - } <nl> - <nl> - static void tensorOrmqr ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor tau = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor c = unpackRetrieveTensor ( raw_message ) ; <nl> - auto side = unpackInteger ( raw_message ) ; <nl> - auto trans = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : ormqr_out ( ra , ra , tau , c , side , trans ) ; <nl> - } <nl> - <nl> - static void tensorPstrf ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor ra = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor rpiv = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - auto uplo = unpackInteger ( raw_message ) ; <nl> - RPCType type = peekType ( raw_message ) ; <nl> - if ( isInteger ( type ) ) { <nl> - auto tol = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : pstrf_out ( ra , rpiv , a , uplo , tol ) ; <nl> - } else if ( isFloat ( type ) ) { <nl> - auto tol = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : pstrf_out ( ra , rpiv , a , uplo , tol ) ; <nl> - } else { <nl> - throw std : : runtime_error ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> deleted file mode 100644 <nl> index f22f94c7f7ae . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / dispatch / TensorMath . cpp <nl> ppp / dev / null <nl> <nl> - <nl> - static void tensorFill ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - RPCType type = peekType ( raw_message ) ; <nl> - if ( isInteger ( type ) ) { <nl> - auto value = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - t . fill_ ( value ) ; <nl> - } else if ( isFloat ( type ) ) { <nl> - auto value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - t . fill_ ( value ) ; <nl> - } else { <nl> - throw std : : runtime_error ( " expected a scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorMaskedFill ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor mask = unpackRetrieveTensor ( raw_message ) ; <nl> - RPCType type = peekType ( raw_message ) ; <nl> - if ( isInteger ( type ) ) { <nl> - auto value = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - t . masked_fill_ ( mask , value ) ; <nl> - } else if ( isFloat ( type ) ) { <nl> - auto value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - t . masked_fill_ ( mask , value ) ; <nl> - } else { <nl> - throw std : : runtime_error ( " expected a scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorMaskedCopy ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor mask = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - t . masked_scatter_ ( mask , src ) ; <nl> - } <nl> - <nl> - static void tensorMaskedSelect ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor mask = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : masked_select_out ( t , src , mask ) ; <nl> - } <nl> - <nl> - static void tensorNonzero ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor subscript = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : nonzero_out ( subscript , tensor ) ; <nl> - int64_t numel = subscript . sizes ( ) . size ( ) > 0 ? subscript . sizes ( ) [ 0 ] : 0 ; <nl> - sendValueToMaster ( numel ) ; <nl> - } <nl> - <nl> - static void tensorIndexSelect ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dim = unpackInteger ( raw_message ) ; <nl> - at : : Tensor index = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : index_select_out ( tensor , src , dim , index ) ; <nl> - } <nl> - <nl> - static void tensorIndexCopy ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int dim = unpackInteger ( raw_message ) ; <nl> - at : : Tensor index = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . index_copy_ ( dim , index , src ) ; <nl> - } <nl> - <nl> - static void tensorIndexAdd ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int dim = unpackInteger ( raw_message ) ; <nl> - at : : Tensor index = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . index_add_ ( dim , index , src ) ; <nl> - } <nl> - <nl> - static void tensorIndexFill ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int dim = unpackInteger ( raw_message ) ; <nl> - at : : Tensor index = unpackRetrieveTensor ( raw_message ) ; <nl> - RPCType type = peekType ( raw_message ) ; <nl> - if ( isInteger ( type ) ) { <nl> - auto val = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . index_fill_ ( dim , index , val ) ; <nl> - } else if ( isFloat ( type ) ) { <nl> - auto val = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . index_fill_ ( dim , index , val ) ; <nl> - } else { <nl> - throw std : : runtime_error ( " expected a scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorDiag ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - int k = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : diag_out ( r , t , k ) ; <nl> - } <nl> - <nl> - static void tensorEye ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int64_t n = unpackInteger ( raw_message ) ; <nl> - int64_t m = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : eye_out ( tensor , n , m ) ; <nl> - } <nl> - <nl> - static void tensorRange ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - RPCType type = peekType ( raw_message ) ; <nl> - if ( isInteger ( type ) ) { <nl> - int64_t xmin = unpackInteger ( raw_message ) ; <nl> - int64_t xmax = unpackInteger ( raw_message ) ; <nl> - int64_t step = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : range_out ( r , xmin , xmax , step ) ; <nl> - } else if ( isFloat ( type ) ) { <nl> - double xmin = unpackFloat ( raw_message ) ; <nl> - double xmax = unpackFloat ( raw_message ) ; <nl> - double step = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : range_out ( r , xmin , xmax , step ) ; <nl> - } else { <nl> - throw std : : runtime_error ( " expected a scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorRandperm ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - int64_t n = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : randperm_out ( r , n , _generator ) ; <nl> - } <nl> - <nl> - static void tensorSort ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor rt = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor ri = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int desc = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : sort_out ( rt , ri , tensor , dimension , desc ) ; <nl> - } <nl> - <nl> - static void tensorTopk ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor rt = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor ri = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int64_t k = unpackInteger ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int dir = unpackInteger ( raw_message ) ; <nl> - int sorted = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : topk_out ( rt , ri , tensor , k , dimension , dir , sorted ) ; <nl> - } <nl> - <nl> - static void tensorTril ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - int64_t k = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : tril_out ( r , t , k ) ; <nl> - } <nl> - <nl> - static void tensorTriu ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - int64_t k = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : triu_out ( r , t , k ) ; <nl> - } <nl> - <nl> - static void tensorCatArray ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor result = unpackRetrieveTensor ( raw_message ) ; <nl> - int numInputs = unpackInteger ( raw_message ) ; <nl> - std : : vector < at : : Tensor > inputs ( numInputs ) ; <nl> - for ( size_t i = 0 ; i < numInputs ; i + + ) <nl> - inputs [ i ] = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : cat_out ( result , inputs , dimension ) ; <nl> - } <nl> - <nl> - static void tensorEqual ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor ta = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor tb = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - int64_t response = ta . equal ( tb ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } <nl> - <nl> - static void tensorTpow ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - if ( at : : isIntegralType ( t . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : pow_out ( r , t , value ) ; <nl> - } else if ( at : : isFloatingType ( t . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : pow_out ( r , t , value ) ; <nl> - } else { <nl> - throw std : : runtime_error ( " expected a scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - # define TENSOR_IMPLEMENT_LOGICAL ( NAME , METHODNAME ) \ <nl> - static void tensor # # NAME # # Value ( rpc : : RPCMessage & raw_message ) { \ <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; \ <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; \ <nl> - if ( at : : isIntegralType ( t . type ( ) . scalarType ( ) ) ) { \ <nl> - int64_t value = ( int64_t ) unpackInteger ( raw_message ) ; \ <nl> - finalize ( raw_message ) ; \ <nl> - at : : METHODNAME # # _out ( t , r , value ) ; \ <nl> - } else if ( at : : isFloatingType ( t . type ( ) . scalarType ( ) ) ) { \ <nl> - double value = unpackFloat ( raw_message ) ; \ <nl> - finalize ( raw_message ) ; \ <nl> - at : : METHODNAME # # _out ( t , r , value ) ; \ <nl> - } else { \ <nl> - throw std : : runtime_error ( " expected scalar type " ) ; \ <nl> - } \ <nl> - } \ <nl> - static void tensor # # NAME # # ValueT ( rpc : : RPCMessage & raw_message ) { \ <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; \ <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; \ <nl> - if ( at : : isIntegralType ( t . type ( ) . scalarType ( ) ) ) { \ <nl> - int64_t value = ( int64_t ) unpackInteger ( raw_message ) ; \ <nl> - finalize ( raw_message ) ; \ <nl> - at : : METHODNAME # # _out ( r , t , value ) ; \ <nl> - } else if ( at : : isFloatingType ( t . type ( ) . scalarType ( ) ) ) { \ <nl> - double value = unpackFloat ( raw_message ) ; \ <nl> - finalize ( raw_message ) ; \ <nl> - at : : METHODNAME # # _out ( r , t , value ) ; \ <nl> - } else { \ <nl> - throw std : : runtime_error ( " expected scalar type " ) ; \ <nl> - } \ <nl> - } \ <nl> - static void tensor # # NAME # # Tensor ( rpc : : RPCMessage & raw_message ) { \ <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; \ <nl> - at : : Tensor ta = unpackRetrieveTensor ( raw_message ) ; \ <nl> - at : : Tensor tb = unpackRetrieveTensor ( raw_message ) ; \ <nl> - finalize ( raw_message ) ; \ <nl> - at : : METHODNAME # # _out ( ta , r , tb ) ; \ <nl> - } \ <nl> - static void tensor # # NAME # # TensorT ( rpc : : RPCMessage & raw_message ) { \ <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; \ <nl> - at : : Tensor ta = unpackRetrieveTensor ( raw_message ) ; \ <nl> - at : : Tensor tb = unpackRetrieveTensor ( raw_message ) ; \ <nl> - finalize ( raw_message ) ; \ <nl> - at : : METHODNAME # # _out ( r , ta , tb ) ; \ <nl> - } \ <nl> - <nl> - TENSOR_IMPLEMENT_LOGICAL ( Lt , lt ) <nl> - TENSOR_IMPLEMENT_LOGICAL ( Gt , lt ) <nl> - TENSOR_IMPLEMENT_LOGICAL ( Le , le ) <nl> - TENSOR_IMPLEMENT_LOGICAL ( Ge , ge ) <nl> - TENSOR_IMPLEMENT_LOGICAL ( Eq , eq ) <nl> - TENSOR_IMPLEMENT_LOGICAL ( Ne , ne ) <nl> - <nl> - # undef TENSOR_IMPLEMENT_LOGICAL <nl> - <nl> - # define TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( NAME , METHODNAME ) \ <nl> - static void tensor # # NAME ( rpc : : RPCMessage & raw_message ) { \ <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; \ <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; \ <nl> - finalize ( raw_message ) ; \ <nl> - at : : METHODNAME # # _out ( r , t ) ; \ <nl> - } \ <nl> - <nl> - # define TENSOR_IMPLEMENT_POINTWISE_VALUE_FUNCTION ( NAME , METHODNAME ) \ <nl> - static void tensor # # NAME ( rpc : : RPCMessage & raw_message ) { \ <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; \ <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; \ <nl> - if ( at : : isIntegralType ( t . type ( ) . scalarType ( ) ) ) { \ <nl> - int64_t value = ( int64_t ) unpackInteger ( raw_message ) ; \ <nl> - finalize ( raw_message ) ; \ <nl> - at : : METHODNAME # # _out ( r , t , value ) ; \ <nl> - } else if ( at : : isFloatingType ( t . type ( ) . scalarType ( ) ) ) { \ <nl> - double value = unpackFloat ( raw_message ) ; \ <nl> - finalize ( raw_message ) ; \ <nl> - at : : METHODNAME # # _out ( r , t , value ) ; \ <nl> - } else { \ <nl> - throw std : : runtime_error ( " expected scalar type " ) ; \ <nl> - } \ <nl> - } \ <nl> - <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Abs , abs ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Sigmoid , sigmoid ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Log , log ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Log10 , log10 ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Log1p , log1p ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Log2 , log2 ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Exp , exp ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Expm1 , expm1 ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Cos , cos ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Acos , acos ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Cosh , cosh ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Sin , sin ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Asin , asin ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Sinh , sinh ) <nl> - <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Tan , tan ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Atan , atan ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Tanh , tanh ) <nl> - TENSOR_IMPLEMENT_POINTWISE_VALUE_FUNCTION ( Pow , pow ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Sqrt , sqrt ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Rsqrt , rsqrt ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Ceil , ceil ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Floor , floor ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Round , round ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Trunc , trunc ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Frac , frac ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Neg , neg ) <nl> - TENSOR_IMPLEMENT_POINTWISE_FUNCTION ( Cinv , inverse ) <nl> - <nl> - # undef TENSOR_IMPLEMENT_POINTWISE_VALUE_FUNCTION <nl> - # undef TENSOR_IMPLEMENT_POINTWISE_FUNCTION <nl> - <nl> - static void tensorAtan2 ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor tx = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor ty = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : atan2_out ( r , tx , ty ) ; <nl> - } <nl> - <nl> - static void tensorLerp ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor a = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor b = unpackRetrieveTensor ( raw_message ) ; <nl> - if ( at : : isIntegralType ( r . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : lerp_out ( r , a , b , value ) ; <nl> - } else if ( at : : isFloatingType ( r . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : lerp_out ( r , a , b , value ) ; <nl> - } else { <nl> - throw std : : runtime_error ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorMean ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : mean_out ( r , t , dimension , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorStd ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int biased = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : std_out ( r , t , dimension , biased , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorVar ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int biased = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : var_out ( r , t , dimension , biased , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorNorm ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor t = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - if ( at : : isIntegralType ( r . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : norm_out ( r , t , value , dimension , keepdim ) ; <nl> - } else if ( at : : isFloatingType ( r . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : norm_out ( r , t , value , dimension , keepdim ) ; <nl> - } else { <nl> - throw std : : runtime_error ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorNormall ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( r . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - int64_t response = r . norm ( value ) . toCLong ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } else if ( at : : isFloatingType ( r . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - double response = r . norm ( value ) . toCDouble ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorRenorm ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor res = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( res . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - int64_t maxnorm = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - at : : renorm_out ( res , src , value , dimension , maxnorm ) ; <nl> - } else if ( at : : isFloatingType ( res . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - double maxnorm = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - at : : renorm_out ( res , src , value , dimension , maxnorm ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorDist ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t value = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - int64_t response = src . dist ( tensor , value ) . toCLong ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double value = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - double response = src . dist ( tensor , value ) . toCDouble ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorMeanall ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t response = tensor . mean ( ) . toCLong ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double response = tensor . mean ( ) . toCLong ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorVarall ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int biased = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t response = tensor . var ( ( bool ) biased ) . toCLong ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double response = tensor . var ( ( bool ) biased ) . toCDouble ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorStdall ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int biased = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - int64_t response = tensor . std ( ( bool ) biased ) . toCLong ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } else if ( at : : isFloatingType ( tensor . type ( ) . scalarType ( ) ) ) { <nl> - double response = tensor . std ( ( bool ) biased ) . toCDouble ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorLinspace ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - int64_t n = unpackInteger ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( r . type ( ) . scalarType ( ) ) ) { <nl> - int64_t a = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - int64_t b = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : linspace_out ( r , a , b , n ) ; <nl> - } else if ( at : : isFloatingType ( r . type ( ) . scalarType ( ) ) ) { <nl> - double a = unpackFloat ( raw_message ) ; <nl> - double b = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : linspace_out ( r , a , b , n ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorLogspace ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - int64_t n = unpackInteger ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( r . type ( ) . scalarType ( ) ) ) { <nl> - int64_t a = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - int64_t b = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : logspace_out ( r , a , b , n ) ; <nl> - } else if ( at : : isFloatingType ( r . type ( ) . scalarType ( ) ) ) { <nl> - double a = unpackFloat ( raw_message ) ; <nl> - double b = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : logspace_out ( r , a , b , n ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorRand ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - THLongStorage * size = unpackTHLongStorage ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : ArrayRef < int64_t > sizeRef ( THLongStorage_data ( size ) , THLongStorage_size ( size ) ) ; <nl> - at : : rand_out ( r , sizeRef , _generator ) ; <nl> - THLongStorage_free ( size ) ; <nl> - } <nl> - <nl> - static void tensorRandn ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor r = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - THLongStorage * size = unpackTHLongStorage ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : ArrayRef < int64_t > sizeRef ( THLongStorage_data ( size ) , THLongStorage_size ( size ) ) ; <nl> - at : : randn_out ( r , sizeRef , _generator ) ; <nl> - THLongStorage_free ( size ) ; <nl> - } <nl> - <nl> - static void tensorHistc ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor hist = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - int64_t nbins = unpackInteger ( raw_message ) ; <nl> - <nl> - if ( at : : isIntegralType ( hist . type ( ) . scalarType ( ) ) ) { <nl> - int64_t minvalue = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - int64_t maxvalue = ( int64_t ) unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : histc_out ( hist , tensor , nbins , minvalue , maxvalue ) ; <nl> - } else if ( at : : isFloatingType ( hist . type ( ) . scalarType ( ) ) ) { <nl> - double minvalue = unpackFloat ( raw_message ) ; <nl> - double maxvalue = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : histc_out ( hist , tensor , nbins , minvalue , maxvalue ) ; <nl> - } else { <nl> - throw std : : invalid_argument ( " expected scalar type " ) ; <nl> - } <nl> - } <nl> - <nl> - static void tensorLogicalAndAll ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - int64_t response = tensor . all ( ) . toCLong ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } <nl> - <nl> - static void tensorLogicalAnyAll ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - int64_t response = tensor . any ( ) . toCLong ( ) ; <nl> - sendValueToMaster ( response ) ; <nl> - } <nl> - <nl> - static void tensorLogicalAnd ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : all_out ( tensor , src , dimension , keepdim ) ; <nl> - } <nl> - <nl> - static void tensorLogicalAny ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Tensor src = unpackRetrieveTensor ( raw_message ) ; <nl> - int dimension = unpackInteger ( raw_message ) ; <nl> - int keepdim = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : any_out ( tensor , src , dimension , keepdim ) ; <nl> - } <nl> deleted file mode 100644 <nl> index e699b3074f04 . . 000000000000 <nl> mmm a / torch / lib / THD / master_worker / worker / dispatch / TensorRandom . cpp <nl> ppp / dev / null <nl> <nl> - <nl> - static void tensorRandom ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . random_ ( _generator ) ; <nl> - } <nl> - <nl> - static void tensorGeometric ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - double p = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . geometric_ ( p , _generator ) ; <nl> - } <nl> - <nl> - static void tensorBernoulli ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - double p = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - throw std : : runtime_error ( " bernoulli not yet wrapped in ATen " ) ; <nl> - / * tensor . bernoulli_ ( p , _generator ) ; * / <nl> - } <nl> - <nl> - static void tensorBernoulli_FloatTensor ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - at : : Tensor p = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - throw std : : runtime_error ( " bernoulli not yet wrapped in ATen " ) ; <nl> - / * tensor - > bernoulli_FloatTensor ( _generator , * p ) ; * / <nl> - } <nl> - <nl> - static void tensorBernoulli_DoubleTensor ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - at : : Tensor p = unpackRetrieveTensor ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - <nl> - throw std : : runtime_error ( " bernoulli not yet wrapped in ATen " ) ; <nl> - / * tensor - > bernoulli_DoubleTensor ( _generator , * p ) ; * / <nl> - } <nl> - <nl> - static void tensorUniform ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - double a = unpackFloat ( raw_message ) ; <nl> - double b = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . uniform_ ( a , b , _generator ) ; <nl> - } <nl> - <nl> - static void tensorNormal ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - double mean = unpackFloat ( raw_message ) ; <nl> - double stdv = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . normal_ ( mean , stdv , _generator ) ; <nl> - } <nl> - <nl> - static void tensorExponential ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - double lambda = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . exponential_ ( lambda , _generator ) ; <nl> - } <nl> - <nl> - static void tensorCauchy ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - double median = unpackFloat ( raw_message ) ; <nl> - double sigma = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . cauchy_ ( median , sigma , _generator ) ; <nl> - } <nl> - <nl> - static void tensorLogNormal ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - double mean = unpackFloat ( raw_message ) ; <nl> - double stdv = unpackFloat ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - tensor . log_normal_ ( mean , stdv , _generator ) ; <nl> - } <nl> - <nl> - static void tensorMultinomial ( rpc : : RPCMessage & raw_message ) { <nl> - at : : Tensor tensor = unpackRetrieveTensor ( raw_message ) ; <nl> - at : : Generator * _generator = unpackRetrieveGenerator ( raw_message ) ; <nl> - at : : Tensor prob_dist = unpackRetrieveTensor ( raw_message ) ; <nl> - int n_sample = unpackInteger ( raw_message ) ; <nl> - int with_replacement = unpackInteger ( raw_message ) ; <nl> - finalize ( raw_message ) ; <nl> - at : : multinomial_out ( tensor , prob_dist , n_sample , with_replacement , _generator ) ; <nl> - } <nl> deleted file mode 100644 <nl> index a07a2cb03feb . . 000000000000 <nl> mmm a / torch / lib / THD / test / command_channel_smoke . cpp <nl> ppp / dev / null <nl> <nl> - # include " . . / master_worker / common / CommandChannel . hpp " <nl> - # include " TestUtils . hpp " <nl> - <nl> - # include < cassert > <nl> - # include < cerrno > <nl> - # include < cstdlib > <nl> - # include < exception > <nl> - # include < mutex > <nl> - # include < string > <nl> - # include < system_error > <nl> - # include < thread > <nl> - <nl> - using namespace thd ; <nl> - <nl> - std : : vector < std : : thread > g_all_workers ; <nl> - std : : mutex g_mutex ; <nl> - std : : unique_ptr < Barrier > g_barrier ; <nl> - <nl> - void init_worker ( const int & rank , const std : : string & master_addr ) { <nl> - g_mutex . lock ( ) ; <nl> - setenv ( RANK_ENV , std : : to_string ( rank ) . data ( ) , 1 ) ; <nl> - setenv ( MASTER_ADDR_ENV , master_addr . data ( ) , 1 ) ; <nl> - auto channel = std : : make_shared < thd : : WorkerCommandChannel > ( thd : : getInitConfig ( " env : / / " ) ) ; / / reads all env variable <nl> - g_mutex . unlock ( ) ; <nl> - <nl> - assert ( channel - > init ( ) ) ; <nl> - <nl> - auto msg = channel - > recvMessage ( ) ; <nl> - std : : string expected = std : : string ( " hello to worker " ) + <nl> - std : : to_string ( rank ) + " from master " ; <nl> - fprintf ( stderr , " Worker % d : received ' % . * s ' \ n " , rank , <nl> - ( int ) msg . get ( ) - > bytes ( ) . length ( ) , msg . get ( ) - > bytes ( ) . data ( ) ) ; <nl> - assert ( expected . compare ( msg . get ( ) - > bytes ( ) . to_string ( ) ) = = 0 ) ; <nl> - <nl> - / * <nl> - * We need to wait until master will do all receiving and sending . This <nl> - * is because when worker is destroyed it closes all sockets what results in <nl> - * triggering ` poll ` function in master ' s error_handler and throwing exception . <nl> - * / <nl> - g_barrier - > wait ( ) ; <nl> - } <nl> - <nl> - void init_master ( int world_size , const std : : string & master_port ) { <nl> - g_mutex . lock ( ) ; <nl> - setenv ( WORLD_SIZE_ENV , std : : to_string ( world_size ) . data ( ) , 1 ) ; <nl> - setenv ( RANK_ENV , " 0 " , 1 ) ; <nl> - setenv ( MASTER_PORT_ENV , master_port . data ( ) , 1 ) ; <nl> - auto channel = std : : make_shared < thd : : MasterCommandChannel > ( thd : : getInitConfig ( " env : / / " ) ) ; / / reads all env variable <nl> - g_mutex . unlock ( ) ; <nl> - <nl> - assert ( channel - > init ( ) ) ; <nl> - <nl> - for ( int worker_rank = 1 ; worker_rank < world_size ; + + worker_rank ) { <nl> - rpc : : ByteArray arr ; <nl> - arr . append ( " hello to worker " , sizeof ( " hello to worker " ) - 1 ) ; <nl> - arr . append ( std : : to_string ( worker_rank ) . c_str ( ) , std : : to_string ( worker_rank ) . size ( ) ) ; <nl> - arr . append ( " from master " , sizeof ( " from master " ) - 1 ) ; <nl> - <nl> - fprintf ( stderr , " master : about to send a message to worker % d \ n " , worker_rank ) ; <nl> - auto rpc_msg = std : : unique_ptr < rpc : : RPCMessage > ( new rpc : : RPCMessage ( arr ) ) ; <nl> - channel - > sendMessage ( std : : move ( rpc_msg ) , worker_rank ) ; <nl> - } <nl> - <nl> - g_barrier - > wait ( ) ; <nl> - <nl> - / / wait for all workers to finish <nl> - for ( auto & worker : g_all_workers ) { <nl> - worker . join ( ) ; <nl> - } <nl> - } <nl> - <nl> - void run_test_case ( const std : : string & name , int world_size , <nl> - const std : : string & master_addr , const std : : string & master_port ) { <nl> - g_barrier . reset ( new Barrier ( world_size ) ) ; <nl> - for ( int rank = 1 ; rank < world_size ; + + rank ) { <nl> - g_all_workers . push_back ( <nl> - std : : thread ( init_worker , rank , master_addr + " : " + master_port ) <nl> - ) ; <nl> - } <nl> - <nl> - std : : thread master_thread ( init_master , world_size , master_port ) ; <nl> - master_thread . join ( ) ; <nl> - g_all_workers . clear ( ) ; <nl> - <nl> - fprintf ( stderr , " \ nPassed % s : \ n " <nl> - " world size = \ t \ t % d \ n " <nl> - " master address = \ t % s \ n " <nl> - " master port = \ t \ t % s \ n " <nl> - " mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - \ n \ n " , <nl> - name . c_str ( ) , world_size , master_addr . c_str ( ) , master_port . c_str ( ) ) ; <nl> - } <nl> - <nl> - int main ( ) { <nl> - int world_size ; <nl> - std : : string master_addr ; <nl> - std : : string master_port ; <nl> - std : : string test_name ; <nl> - <nl> - try { <nl> - test_name = " Master test " ; <nl> - world_size = 1 ; <nl> - master_addr = " 127 . 0 . 0 . 1 " ; <nl> - master_port = " 55555 " ; <nl> - run_test_case ( test_name , world_size , master_addr , master_port ) ; <nl> - <nl> - test_name = " Basic test " ; <nl> - world_size = 4 ; <nl> - master_addr = " 127 . 0 . 0 . 1 " ; <nl> - master_port = " 55555 " ; <nl> - run_test_case ( test_name , world_size , master_addr , master_port ) ; <nl> - <nl> - test_name = " Many workers test " ; <nl> - world_size = 12 ; <nl> - master_addr = " 127 . 0 . 0 . 1 " ; <nl> - master_port = " 55555 " ; <nl> - run_test_case ( test_name , world_size , master_addr , master_port ) ; <nl> - <nl> - test_name = " IPv6 test " ; <nl> - world_size = 12 ; <nl> - master_addr = " 127 . 0 . 0 . 1 " ; <nl> - master_port = " 55555 " ; <nl> - run_test_case ( test_name , world_size , master_addr , master_port ) ; <nl> - <nl> - test_name = " Hostname resolution test " ; <nl> - world_size = 12 ; <nl> - master_addr = " localhost " ; <nl> - master_port = " 55555 " ; <nl> - run_test_case ( test_name , world_size , master_addr , master_port ) ; <nl> - } catch ( const std : : exception & e ) { <nl> - throw std : : runtime_error ( <nl> - " test for world size = " + std : : to_string ( world_size ) + <nl> - " , master address = " + master_addr + " , master port = " + <nl> - master_port + " failed because of : ` " + e . what ( ) + " ` " ) ; <nl> - } <nl> - <nl> - fprintf ( stdout , " OK \ n " ) ; <nl> - return 0 ; <nl> - } <nl> deleted file mode 100644 <nl> index cc4f437cb905 . . 000000000000 <nl> mmm a / torch / lib / THD / test / rpc_serialization . cpp <nl> ppp / dev / null <nl> <nl> - # include < cassert > <nl> - # include < climits > <nl> - # include < cstdint > <nl> - # include < iostream > <nl> - # include < typeinfo > <nl> - # include < vector > <nl> - <nl> - # include < THPP / Type . hpp > <nl> - <nl> - # include " . . / master_worker / common / RPC . hpp " <nl> - # include " TH / THStorageFunctions . h " <nl> - <nl> - using namespace std ; <nl> - using namespace thd ; <nl> - using namespace thd : : rpc ; <nl> - <nl> - constexpr ptrdiff_t STORAGE_SIZE = 10 ; <nl> - constexpr size_t VEC_SIZE = 3 ; <nl> - <nl> - int main ( ) { <nl> - THLongStorage * storage1 = THLongStorage_newWithSize ( STORAGE_SIZE ) ; <nl> - int64_t * data = storage1 - > data ; <nl> - for ( int64_t i = 0 ; i < STORAGE_SIZE ; i + + ) <nl> - data [ i ] = i ; <nl> - std : : vector < int64_t > vec ( VEC_SIZE , 7 ) ; / / VEC_SIZE sevens <nl> - std : : unique_ptr < RPCMessage > msg_ptr = <nl> - packMessage ( 1 , 1 . 0f , 100l , - 12 , LLONG_MAX , storage1 , vec ) ; <nl> - auto & msg = * msg_ptr ; <nl> - <nl> - uint16_t fid = unpackFunctionId ( msg ) ; <nl> - assert ( fid = = 1 ) ; <nl> - <nl> - assert ( peekType ( msg ) = = thpp : : Type : : FLOAT ) ; <nl> - double arg1 = unpackFloat ( msg ) ; <nl> - assert ( arg1 = = 1 . 0 ) ; <nl> - <nl> - assert ( peekType ( msg ) = = thpp : : Type : : LONG ) ; <nl> - int64_t arg2 = unpackInteger ( msg ) ; <nl> - assert ( arg2 = = 100 ) ; <nl> - <nl> - assert ( peekType ( msg ) = = thpp : : Type : : INT ) ; <nl> - int64_t arg3 = unpackInteger ( msg ) ; <nl> - assert ( arg3 = = - 12 ) ; <nl> - <nl> - assert ( peekType ( msg ) = = thpp : : Type : : LONG_LONG ) ; <nl> - int64_t arg4 = unpackInteger ( msg ) ; <nl> - assert ( arg4 = = LLONG_MAX ) ; <nl> - <nl> - assert ( peekType ( msg ) = = thpp : : Type : : LONG_STORAGE ) ; <nl> - THLongStorage * storage2 = unpackTHLongStorage ( msg ) ; <nl> - assert ( storage2 - > size = = STORAGE_SIZE ) ; <nl> - for ( int64_t i = 0 ; i < STORAGE_SIZE ; i + + ) <nl> - assert ( storage2 - > data [ i ] = = i ) ; <nl> - <nl> - int vec_size = unpackInteger ( msg ) ; <nl> - assert ( vec_size = = VEC_SIZE ) ; <nl> - for ( int i = 0 ; i < VEC_SIZE ; i + + ) <nl> - assert ( unpackInteger ( msg ) = = 7 ) ; <nl> - <nl> - assert ( msg . isEmpty ( ) ) ; <nl> - try { <nl> - double arg6 = unpackFloat ( msg ) ; <nl> - assert ( false ) ; <nl> - } catch ( exception & e ) { } <nl> - std : : cout < < " OK " < < std : : endl ; <nl> - return 0 ; <nl> - } <nl>
Delete THD master_worker ( )
pytorch/pytorch
227635142f124bfb2c2626916d237cb0c6033092
2018-08-22T15:54:36Z
mmm a / googlemock / docs / cheat_sheet . md <nl> ppp b / googlemock / docs / cheat_sheet . md <nl> Matcher | Description <nl> | ` IsTrue ( ) ` | ` argument ` evaluates to ` true ` in a Boolean context . | <nl> | ` IsNull ( ) ` | ` argument ` is a ` NULL ` pointer ( raw or smart ) . | <nl> | ` NotNull ( ) ` | ` argument ` is a non - null pointer ( raw or smart ) . | <nl> - | ` Optional ( m ) ` | ` argument ` is ` optional < > ` that contains a value matching ` m ` . | <nl> + | ` Optional ( m ) ` | ` argument ` is ` optional < > ` that contains a value matching ` m ` . ( For testing whether an ` optional < > ` is set , check for equality with ` nullopt ` . You may need to use ` Eq ( nullopt ) ` if the inner type doesn ' t have ` = = ` . ) | <nl> | ` VariantWith < T > ( m ) ` | ` argument ` is ` variant < > ` that holds the alternative of type T with a value matching ` m ` . | <nl> | ` Ref ( variable ) ` | ` argument ` is a reference to ` variable ` . | <nl> | ` TypedEq < type > ( value ) ` | ` argument ` has type ` type ` and is equal to ` value ` . You may need to use this instead of ` Eq ( value ) ` when the mock function is overloaded . | <nl>
Googletest export
google/googletest
4bf466236dbe1db812fab9264d800175eec1cd24
2019-11-20T19:16:45Z
mmm a / xbmc / cores / dvdplayer / DVDCodecs / Video / VAAPI . cpp <nl> ppp b / xbmc / cores / dvdplayer / DVDCodecs / Video / VAAPI . cpp <nl> bool CDecoder : : Open ( AVCodecContext * avctx , const enum PixelFormat fmt , unsigned <nl> else <nl> m_vaapiConfig . maxReferences = 2 ; <nl> <nl> - m_vaapiConfig . maxReferences + = surfaces ; <nl> + / / add an extra surface for safety , some faulty material <nl> + / / make ffmpeg require more buffers <nl> + m_vaapiConfig . maxReferences + = surfaces + 1 ; <nl> <nl> if ( ! ConfigVAAPI ( ) ) <nl> { <nl>
Merge pull request from FernetMenta / vaapifix
xbmc/xbmc
2b5680849881b0b6de9d736c5438e8e342746e98
2014-12-31T07:10:07Z
mmm a / lib / AST / GenericSignatureBuilder . cpp <nl> ppp b / lib / AST / GenericSignatureBuilder . cpp <nl> void GenericSignatureBuilder : : enumerateRequirements ( llvm : : function_ref < <nl> / / to the next . <nl> / / FIXME : Distinguish between explicit and inferred here ? <nl> auto otherPA = nextAnchor - > anchor ; <nl> - deferredSameTypeRequirement = [ & f , archetype , otherPA , this ] { <nl> + deferredSameTypeRequirement = [ & f , archetype , otherPA ] { <nl> f ( RequirementKind : : SameType , archetype , otherPA , <nl> RequirementSource : : forAbstract ( archetype ) ) ; <nl> } ; <nl> mmm a / lib / Driver / DependencyGraph . cpp <nl> ppp b / lib / Driver / DependencyGraph . cpp <nl> LoadResult DependencyGraphImpl : : loadFromBuffer ( const void * node , <nl> } ; <nl> <nl> auto providesCallback = <nl> - [ this , node , & provides ] ( StringRef name , DependencyKind kind , <nl> + [ & provides ] ( StringRef name , DependencyKind kind , <nl> bool isCascading ) - > LoadResult { <nl> assert ( isCascading ) ; <nl> auto iter = std : : find_if ( provides . begin ( ) , provides . end ( ) , <nl> mmm a / lib / Parse / ParseSIL . cpp <nl> ppp b / lib / Parse / ParseSIL . cpp <nl> bool Parser : : parseDeclSIL ( ) { <nl> FunctionState . ParsedTypeCallback = OldParsedTypeCallback ; <nl> } ; <nl> <nl> - FunctionState . ParsedTypeCallback = [ & OpenedArchetypesTracker , <nl> - & FunctionState ] ( Type ty ) { <nl> + FunctionState . ParsedTypeCallback = [ & OpenedArchetypesTracker ] ( Type ty ) { <nl> OpenedArchetypesTracker . registerUsedOpenedArchetypes ( <nl> ty - > getCanonicalType ( ) ) ; <nl> } ; <nl> mmm a / lib / PrintAsObjC / PrintAsObjC . cpp <nl> ppp b / lib / PrintAsObjC / PrintAsObjC . cpp <nl> class ObjCPrinter : private DeclVisitor < ObjCPrinter > , <nl> void printCollectionElement ( Type ty ) { <nl> ASTContext & ctx = M . getASTContext ( ) ; <nl> <nl> - auto isSwiftNewtype = [ & ctx ] ( const StructDecl * SD ) - > bool { <nl> + auto isSwiftNewtype = [ ] ( const StructDecl * SD ) - > bool { <nl> if ( ! SD ) <nl> return false ; <nl> auto * clangDecl = SD - > getClangDecl ( ) ; <nl> class ModuleWriter { <nl> / / alphabetically first . <nl> auto mismatch = <nl> std : : mismatch ( lhsProtos . begin ( ) , lhsProtos . end ( ) , rhsProtos . begin ( ) , <nl> - [ getSortName ] ( const ProtocolDecl * nextLHSProto , <nl> - const ProtocolDecl * nextRHSProto ) { <nl> + [ ] ( const ProtocolDecl * nextLHSProto , <nl> + const ProtocolDecl * nextRHSProto ) { <nl> return nextLHSProto - > getName ( ) ! = nextRHSProto - > getName ( ) ; <nl> } ) ; <nl> if ( mismatch . first = = lhsProtos . end ( ) ) <nl> mmm a / lib / SIL / Projection . cpp <nl> ppp b / lib / SIL / Projection . cpp <nl> processUsersOfValue ( ProjectionTree & Tree , <nl> DEBUG ( llvm : : dbgs ( ) < < " " < < * User ) ; <nl> <nl> / / First try to create a Projection for User . <nl> - auto P = Projection : : Projection ( User ) ; <nl> + auto P = Projection ( User ) ; <nl> <nl> / / If we fail to create a projection , add User as a user to this node and <nl> / / continue . <nl> mmm a / lib / SILOptimizer / Transforms / SpeculativeDevirtualizer . cpp <nl> ppp b / lib / SILOptimizer / Transforms / SpeculativeDevirtualizer . cpp <nl> static bool tryToSpeculateTarget ( FullApplySite AI , <nl> / / specific bound class . <nl> auto RemovedIt = std : : remove_if ( Subs . begin ( ) , <nl> Subs . end ( ) , <nl> - [ & ClassType , & M ] ( ClassDecl * Sub ) { <nl> + [ & ClassType ] ( ClassDecl * Sub ) { <nl> auto SubCanTy = Sub - > getDeclaredType ( ) - > getCanonicalType ( ) ; <nl> / / Unbound generic type can override a method from <nl> / / a bound generic class , but this unbound generic <nl> static bool tryToSpeculateTarget ( FullApplySite AI , <nl> if ( auto EMT = SubType . getAs < AnyMetatypeType > ( ) ) { <nl> auto InstTy = ClassType . getSwiftRValueType ( ) ; <nl> auto * MetaTy = MetatypeType : : get ( InstTy , EMT - > getRepresentation ( ) ) ; <nl> - auto CanMetaTy = CanMetatypeType : : CanTypeWrapper ( MetaTy ) ; <nl> + auto CanMetaTy = CanMetatypeType ( MetaTy ) ; <nl> ClassOrMetatypeType = SILType : : getPrimitiveObjectType ( CanMetaTy ) ; <nl> } <nl> <nl> mmm a / lib / SILOptimizer / Utils / Devirtualize . cpp <nl> ppp b / lib / SILOptimizer / Utils / Devirtualize . cpp <nl> static void getAllSubclasses ( ClassHierarchyAnalysis * CHA , <nl> / / Filter out any subclasses that do not inherit from this <nl> / / specific bound class . <nl> auto RemovedIt = std : : remove_if ( Subs . begin ( ) , Subs . end ( ) , <nl> - [ & ClassType , & M ] ( ClassDecl * Sub ) { <nl> + [ & ClassType ] ( ClassDecl * Sub ) { <nl> auto SubCanTy = Sub - > getDeclaredType ( ) - > getCanonicalType ( ) ; <nl> / / Unbound generic type can override a method from <nl> / / a bound generic class , but this unbound generic <nl> mmm a / lib / SILOptimizer / Utils / Local . cpp <nl> ppp b / lib / SILOptimizer / Utils / Local . cpp <nl> CastOptimizer : : optimizeCheckedCastBranchInst ( CheckedCastBranchInst * Inst ) { <nl> auto EMT = EmiTy . castTo < AnyMetatypeType > ( ) ; <nl> auto * MetaTy = MetatypeType : : get ( LoweredConcreteTy . getSwiftRValueType ( ) , <nl> EMT - > getRepresentation ( ) ) ; <nl> - auto CanMetaTy = CanMetatypeType : : CanTypeWrapper ( MetaTy ) ; <nl> + auto CanMetaTy = CanTypeWrapper < MetatypeType > ( MetaTy ) ; <nl> auto SILMetaTy = SILType : : getPrimitiveObjectType ( CanMetaTy ) ; <nl> SILBuilderWithScope B ( Inst ) ; <nl> auto * MI = B . createMetatype ( FoundIEI - > getLoc ( ) , SILMetaTy ) ; <nl> CastOptimizer : : optimizeCheckedCastBranchInst ( CheckedCastBranchInst * Inst ) { <nl> / / Get the SIL metatype of this type . <nl> auto EMT = EMI - > getType ( ) . castTo < AnyMetatypeType > ( ) ; <nl> auto * MetaTy = MetatypeType : : get ( ConcreteTy , EMT - > getRepresentation ( ) ) ; <nl> - auto CanMetaTy = CanMetatypeType : : CanTypeWrapper ( MetaTy ) ; <nl> + auto CanMetaTy = CanTypeWrapper < MetatypeType > ( MetaTy ) ; <nl> auto SILMetaTy = SILType : : getPrimitiveObjectType ( CanMetaTy ) ; <nl> SILBuilderWithScope B ( Inst ) ; <nl> auto * MI = B . createMetatype ( FoundIERI - > getLoc ( ) , SILMetaTy ) ; <nl> mmm a / lib / Sema / TypeCheckProtocol . cpp <nl> ppp b / lib / Sema / TypeCheckProtocol . cpp <nl> RequirementEnvironment : : RequirementEnvironment ( <nl> GenericTypeParamType : : get ( depth , genericParam - > getIndex ( ) , ctx ) ; <nl> return substGenericParam ; <nl> } , <nl> - [ selfType , concreteType , conformance , conformanceDC , & ctx , & tc ] ( <nl> + [ selfType , concreteType , conformance , conformanceDC , & ctx ] ( <nl> CanType type , Type replacement , ProtocolType * protoType ) <nl> - > Optional < ProtocolConformanceRef > { <nl> auto proto = protoType - > getDecl ( ) ; <nl> void ConformanceChecker : : recordTypeWitness ( AssociatedTypeDecl * assocType , <nl> / / Avoid relying on the lifetime of ' this ' . <nl> const DeclContext * DC = this - > DC ; <nl> diagnoseOrDefer ( assocType , false , <nl> - [ DC , typeDecl , requiredAccessScope , assocType ] ( <nl> + [ DC , typeDecl , requiredAccessScope ] ( <nl> NormalProtocolConformance * conformance ) { <nl> Accessibility requiredAccess = <nl> requiredAccessScope . requiredAccessibilityForDiagnostics ( ) ; <nl>
Merge remote - tracking branch ' origin / master ' into master - next
apple/swift
20546bd45216f9eeb880b1def1ea1ba385bd2bd5
2017-03-21T13:08:51Z
mmm a / tensorflow / compiler / mlir / lite / BUILD <nl> ppp b / tensorflow / compiler / mlir / lite / BUILD <nl> cc_library ( <nl> " / / tensorflow / compiler / mlir / tensorflow : tensorflow_types " , <nl> " / / tensorflow / compiler / mlir / tensorflow : tf_legalize_hlo " , <nl> " / / tensorflow / compiler / mlir / tensorflow : unroll_batch_matmul_pass " , <nl> + " / / tensorflow / compiler / mlir / tensorflow : verification_utils " , <nl> " / / tensorflow / compiler / mlir / xla : xla_legalize_tf " , <nl> " / / tensorflow / compiler / mlir / xla : xla_legalize_tf_with_tf2xla " , <nl> " / / tensorflow / compiler / xla : status " , <nl> cc_library ( <nl> " : validators " , <nl> " / / tensorflow / compiler / mlir / lite / quantization : quantization_lib " , <nl> " / / tensorflow / compiler / mlir / tensorflow " , <nl> + " / / tensorflow / compiler / mlir / tensorflow : verification_utils " , <nl> " @ llvm - project / / llvm : Support " , <nl> " @ llvm - project / / mlir : IR " , <nl> " @ llvm - project / / mlir : Pass " , <nl> mmm a / tensorflow / compiler / mlir / lite / tests / prepare - tf . mlir <nl> ppp b / tensorflow / compiler / mlir / lite / tests / prepare - tf . mlir <nl> func @ PadStridedSliceNewAxisMask2 ( % arg0 : tensor < 4x64x64x1xf32 > ) - > tensor < 1x4x64 <nl> return % 1 : tensor < 1x4x64x64xf32 > <nl> } <nl> <nl> + / / CHECK - LABEL : @ AvoidPadStridedSliceNewAxisMaskOnUnknownShapes <nl> + func @ AvoidPadStridedSliceNewAxisMaskOnUnknownShapes ( % arg0 : tensor < ? x ? xf32 > ) - > tensor < 1x ? x ? x1xf32 > { <nl> + % cst = constant dense < 0 > : tensor < 4xi32 > <nl> + % cst_0 = constant dense < 1 > : tensor < 4xi32 > <nl> + % 0 = " tf . StridedSlice " ( % arg0 , % cst , % cst , % cst_0 ) { begin_mask = 6 : i64 , ellipsis_mask = 0 : i64 , end_mask = 6 : i64 , new_axis_mask = 9 : i64 , shrink_axis_mask = 0 : i64 } : ( tensor < ? x ? xf32 > , tensor < 4xi32 > , tensor < 4xi32 > , tensor < 4xi32 > ) - > tensor < 1x ? x ? x1xf32 > <nl> + return % 0 : tensor < 1x ? x ? x1xf32 > <nl> + <nl> + / / CHECK - NOT : " tf . Reshape " <nl> + / / CHECK : " tf . StridedSlice " <nl> + } <nl> + <nl> / / CHECK - LABEL : @ StridedSliceRewriteMasks <nl> func @ StridedSliceRewriteMasks ( % arg0 : tensor < 8x4x16x2xf32 > ) - > tensor < 8x4x16x1xf32 > { <nl> % cst = " tf . Const " ( ) { device = " " , value = dense < [ 1 , 0 , 1 ] > : tensor < 3xi32 > } : ( ) - > tensor < 3xi32 > <nl> mmm a / tensorflow / compiler / mlir / lite / transforms / prepare_tf . cc <nl> ppp b / tensorflow / compiler / mlir / lite / transforms / prepare_tf . cc <nl> limitations under the License . <nl> # include " tensorflow / compiler / mlir / tensorflow / transforms / einsum . h " <nl> # include " tensorflow / compiler / mlir / tensorflow / transforms / passes . h " <nl> # include " tensorflow / compiler / mlir / tensorflow / transforms / unroll_batch_matmul . h " <nl> + # include " tensorflow / compiler / mlir / tensorflow / utils / verification_utils . h " <nl> # include " tensorflow / compiler / mlir / xla / transforms / passes . h " <nl> <nl> # define DEBUG_TYPE " tf - tfl - legalization " <nl> struct ConvertTFStridedSlice : public RewritePattern { <nl> new_axis_mask > > = 1 ; <nl> } <nl> <nl> + if ( failed ( TF : : VerifyShapeOfReshapeOp ( new_shape ) ) ) return failure ( ) ; <nl> + <nl> const int dim_size = new_shape . size ( ) ; <nl> Location loc = strided_slice_op . getLoc ( ) ; <nl> auto shape_type = <nl> struct ConvertTFStridedSlice : public RewritePattern { <nl> result_shape_data [ i ] = <nl> rewriter . getI32IntegerAttr ( static_cast < int32_t > ( new_shape [ i ] ) ) ; <nl> } <nl> + <nl> auto shape_attr = DenseElementsAttr : : get ( shape_type , result_shape_data ) ; <nl> auto shape = rewriter . create < ConstantOp > ( loc , shape_type , shape_attr ) ; <nl> auto new_output_type = <nl>
Add reshape op verification codes before applying op lowering rules .
tensorflow/tensorflow
e933e37d906e09673e005715d0174fc634aa9891
2020-11-17T03:30:42Z
mmm a / stdlib / core / Bit . swift <nl> ppp b / stdlib / core / Bit . swift <nl> public func < ( lhs : Bit , rhs : Bit ) - > Bool { <nl> <nl> extension Bit : IntegerArithmeticType { <nl> static func _withOverflow ( v : ( Int , overflow : Bool ) ) - > ( Bit , overflow : Bool ) { <nl> - return ( Bit ( rawValue : v . 0 ) ! , v . overflow ) <nl> + if let b = Bit ( rawValue : v . 0 ) { <nl> + return ( b , v . overflow ) <nl> + } else { <nl> + return ( Bit ( rawValue : v . 0 % 2 ) ! , true ) <nl> + } <nl> } <nl> <nl> / / / Add ` lhs ` and ` rhs ` , returning a result and a ` Bool ` that is <nl> mmm a / test / 1_stdlib / Bit . swift <nl> ppp b / test / 1_stdlib / Bit . swift <nl> println ( zero . successor ( ) . rawValue ) <nl> / / CHECK - NEXT : 0 <nl> println ( one . predecessor ( ) . rawValue ) <nl> <nl> + / / CHECK - NEXT : 0 <nl> + println ( ( one & + one ) . rawValue ) <nl> + <nl> / / CHECK : done . <nl> println ( " done . " ) <nl> <nl>
[ stdlib ] fixes bug in Bit overflow
apple/swift
42207c0a21c3731b1201bdcfa145adc411f491ff
2014-12-24T00:40:56Z
mmm a / src / core / ext / client_config / method_config . c <nl> ppp b / src / core / ext / client_config / method_config . c <nl> static const grpc_hash_table_vtable method_config_table_vtable = { <nl> <nl> grpc_method_config_table * grpc_method_config_table_create ( <nl> size_t num_entries , grpc_method_config_table_entry * entries ) { <nl> - grpc_hash_table_entry hash_table_entries [ num_entries ] ; <nl> + grpc_hash_table_entry * hash_table_entries = <nl> + gpr_malloc ( sizeof ( grpc_hash_table_entry ) * num_entries ) ; <nl> for ( size_t i = 0 ; i < num_entries ; + + i ) { <nl> hash_table_entries [ i ] . key = entries [ i ] . method_name ; <nl> hash_table_entries [ i ] . value = entries [ i ] . method_config ; <nl> hash_table_entries [ i ] . vtable = & method_config_table_vtable ; <nl> } <nl> - return grpc_hash_table_create ( num_entries , hash_table_entries ) ; <nl> + grpc_method_config_table * method_config_table = <nl> + grpc_hash_table_create ( num_entries , hash_table_entries ) ; <nl> + gpr_free ( hash_table_entries ) ; <nl> + return method_config_table ; <nl> } <nl> <nl> grpc_method_config_table * grpc_method_config_table_ref ( <nl> grpc_method_config * grpc_method_config_table_get_method_config ( <nl> const char * path_str = grpc_mdstr_as_c_string ( path ) ; <nl> const char * sep = strrchr ( path_str , ' / ' ) + 1 ; <nl> const size_t len = ( size_t ) ( sep - path_str ) ; <nl> - char buf [ len + 2 ] ; / / ' * ' and NUL <nl> + char * buf = gpr_malloc ( len + 2 ) ; / / ' * ' and NUL <nl> memcpy ( buf , path_str , len ) ; <nl> buf [ len ] = ' * ' ; <nl> buf [ len + 1 ] = ' \ 0 ' ; <nl> grpc_mdstr * wildcard_path = grpc_mdstr_from_string ( buf ) ; <nl> + gpr_free ( buf ) ; <nl> method_config = grpc_hash_table_get ( table , wildcard_path ) ; <nl> GRPC_MDSTR_UNREF ( wildcard_path ) ; <nl> } <nl>
Fix Windows build problem .
grpc/grpc
8b4a70e3d33028286b4ae81ebf35e353a2056f8f
2016-10-07T14:33:30Z
mmm a / tensorflow / tools / graph_transforms / fold_constants_lib . cc <nl> ppp b / tensorflow / tools / graph_transforms / fold_constants_lib . cc <nl> Status FoldConstants ( const GraphDef & input_graph_def , <nl> & input_graph , context . input_names , context . output_names , { } , <nl> device_attributes , false / * use_function_convention * / , & metadata ) ) ; <nl> bool was_mutated ; <nl> - TF_RETURN_IF_ERROR ( ConstantFold ( ConstantFoldingOptions ( ) , nullptr , <nl> - Env : : Default ( ) , nullptr , & input_graph , <nl> - & was_mutated ) ) ; <nl> + / / Exclude specified nodes from constant folding . <nl> + ConstantFoldingOptions cf_opts ; <nl> + if ( context . params . count ( " exclude_op " ) > 0 ) { <nl> + const auto & excluded_nodes = context . params . at ( " exclude_op " ) ; <nl> + const std : : set < string > excluded_nodes_set ( excluded_nodes . begin ( ) , <nl> + excluded_nodes . end ( ) ) ; <nl> + cf_opts . consider = [ excluded_nodes_set ] ( const Node * n ) { <nl> + return excluded_nodes_set . find ( n - > op_def ( ) . name ( ) ) = = <nl> + excluded_nodes_set . end ( ) ; <nl> + } ; <nl> + } <nl> + TF_RETURN_IF_ERROR ( ConstantFold ( cf_opts , nullptr , Env : : Default ( ) , nullptr , <nl> + & input_graph , & was_mutated ) ) ; <nl> GraphDef folded_graph_def ; <nl> input_graph . ToGraphDef ( & folded_graph_def ) ; <nl> GraphDef send_recvs_replaced ; <nl> mmm a / tensorflow / tools / graph_transforms / fold_constants_test . cc <nl> ppp b / tensorflow / tools / graph_transforms / fold_constants_test . cc <nl> See the License for the specific language governing permissions and <nl> limitations under the License . <nl> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * / <nl> <nl> + # include < utility > <nl> + <nl> # include " tensorflow / cc / ops / const_op . h " <nl> # include " tensorflow / cc / ops / image_ops . h " <nl> # include " tensorflow / cc / ops / nn_ops . h " <nl> class ConstantFoldingTest : public : : testing : : Test { <nl> test : : FillIota < float > ( & placeholder_tensor , 1 . 0f ) ; <nl> TestConstantFolding ( graph_def , <nl> { { " placeholder_expect_remains " , placeholder_tensor } } , <nl> - { " output_expect_remains " } ) ; <nl> + { } , { " output_expect_remains " } ) ; <nl> + } <nl> + <nl> + void TestOpExclusionAdd ( ) { <nl> + auto root = tensorflow : : Scope : : NewRootScope ( ) ; <nl> + using namespace : : tensorflow : : ops ; / / NOLINT ( build / namespaces ) <nl> + <nl> + const int width = 100 ; <nl> + <nl> + Tensor a_data ( DT_FLOAT , TensorShape ( { width } ) ) ; <nl> + test : : FillIota < float > ( & a_data , 1 . 0f ) ; <nl> + Output a_const = <nl> + Const ( root . WithOpName ( " a_expect_remains " ) , Input : : Initializer ( a_data ) ) ; <nl> + <nl> + Tensor b_data ( DT_FLOAT , TensorShape ( { width } ) ) ; <nl> + test : : FillIota < float > ( & b_data , 1 . 0f ) ; <nl> + Output b_const = <nl> + Const ( root . WithOpName ( " b_expect_remains " ) , Input : : Initializer ( b_data ) ) ; <nl> + <nl> + Output add = Add ( root . WithOpName ( " add_expect_remains " ) , a_const , b_const ) ; <nl> + <nl> + Output placeholder = <nl> + Placeholder ( root . WithOpName ( " placeholder_expect_remains " ) , DT_FLOAT ) ; <nl> + <nl> + Output mul = <nl> + Mul ( root . WithOpName ( " output_expect_remains " ) , add , placeholder ) ; <nl> + <nl> + GraphDef graph_def ; <nl> + TF_ASSERT_OK ( root . ToGraphDef ( & graph_def ) ) ; <nl> + <nl> + Tensor placeholder_tensor ( DT_FLOAT , TensorShape ( { width } ) ) ; <nl> + test : : FillIota < float > ( & placeholder_tensor , 1 . 0f ) ; <nl> + TestConstantFolding ( graph_def , <nl> + { { " placeholder_expect_remains " , placeholder_tensor } } , <nl> + { " Add " } , { " output_expect_remains " } ) ; <nl> } <nl> <nl> void TestConstantFolding ( const GraphDef & graph_def , <nl> std : : vector < std : : pair < string , Tensor > > inputs , <nl> + std : : vector < string > excluded_ops , <nl> const std : : vector < string > & outputs ) { <nl> std : : unique_ptr < tensorflow : : Session > unfolded_session ( <nl> tensorflow : : NewSession ( tensorflow : : SessionOptions ( ) ) ) ; <nl> class ConstantFoldingTest : public : : testing : : Test { <nl> context . input_names . push_back ( input . first ) ; <nl> } <nl> context . output_names = outputs ; <nl> + context . params [ " exclude_op " ] = std : : move ( excluded_ops ) ; <nl> TF_ASSERT_OK ( <nl> graph_transforms : : FoldConstants ( graph_def , context , & folded_graph_def ) ) ; <nl> <nl> class ConstantFoldingTest : public : : testing : : Test { <nl> <nl> TEST_F ( ConstantFoldingTest , TestSimpleAdd ) { TestSimpleAdd ( ) ; } <nl> <nl> + TEST_F ( ConstantFoldingTest , TestOpExclusionAdd ) { TestOpExclusionAdd ( ) ; } <nl> + <nl> TEST_F ( ConstantFoldingTest , TestReplaceSendRecvs ) { TestReplaceSendRecvs ( ) ; } <nl> <nl> TEST_F ( ConstantFoldingTest , TestRemoveUnusedNodes ) { TestRemoveUnusedNodes ( ) ; } <nl>
Add option to fold_constants to exclude specified ops .
tensorflow/tensorflow
30d7ee5e73e238db0bf43a6af2ac813ade346b2e
2017-07-18T09:27:38Z
mmm a / tensorflow / compiler / xla / service / gpu / ir_emitter_unnested . h <nl> ppp b / tensorflow / compiler / xla / service / gpu / ir_emitter_unnested . h <nl> class IrEmitterUnnested : public IrEmitter , <nl> / / the process . ` scatter ` may be fused , scatter indices are taken from <nl> / / ` scatter_indices_gen ` , updates from ` updates_gen ` . The output buffer is <nl> / / expected to have the operand values in it already . If unique_indices <nl> - / / is false , we will use an atomic update . Using false for unique_indices <nl> - / / is safe only when it is guaranteed that there are no duplicate <nl> - / / indices . <nl> - / / When using unique_indices = true , it is the caller ' s responsibility to <nl> - / / ensure there is no overlap . <nl> + / / is false , we will use an atomic update . Using true for unique_indices <nl> + / / behaves properly only when it is guaranteed that the indices to be <nl> + / / updated do not overlap . The caller is responsible for ensuring this is <nl> + / / the case . <nl> Status EmitScatter ( Thunk * thunk , HloInstruction * scatter , <nl> const llvm_ir : : ElementGenerator & scatter_indices_gen , <nl> const llvm_ir : : ElementGenerator & updates_gen ) ; <nl>
Merge pull request from SIben : fix_documentation_scatter
tensorflow/tensorflow
aaf54f33693a1c5b8807b4cf4769aac80bb10be1
2020-08-27T22:54:28Z
mmm a / lib / SILGen / SILGenDecl . cpp <nl> ppp b / lib / SILGen / SILGenDecl . cpp <nl> class SILGenConformance : public SILWitnessVisitor < SILGenConformance > { <nl> conformance , <nl> } ) ; <nl> <nl> - / / Emit the witness table for the base conformance if it belongs to this <nl> - / / module or is shared . <nl> - if ( conformance - > getDeclContext ( ) - > getParentModule ( ) <nl> - = = SGM . SwiftModule <nl> - | | SGM . Types . getLinkageForProtocolConformance ( <nl> + / / Emit the witness table for the base conformance if it is shared . <nl> + if ( SGM . Types . getLinkageForProtocolConformance ( <nl> conformance - > getRootNormalConformance ( ) , <nl> NotForDefinition ) <nl> = = SILLinkage : : Shared ) <nl> mmm a / test / IRGen / sil_witness_tables . swift <nl> ppp b / test / IRGen / sil_witness_tables . swift <nl> struct Conformer : Q , QQ { <nl> } <nl> <nl> / / CHECK : [ [ EXTERNAL_CONFORMER_EXTERNAL_P_WITNESS_TABLE : @ _TWPV39sil_witness_tables_external_conformance17ExternalConformerS_9ExternalPS_ ] ] = external global i8 * <nl> - / / CHECK : [ [ CONFORMER_P_WITNESS_TABLE : @ _TWPV18sil_witness_tables9ConformerS_1PS_ ] ] = hidden constant [ 4 x i8 * ] [ <nl> + / / CHECK : [ [ CONFORMER_Q_WITNESS_TABLE : @ _TWPV18sil_witness_tables9ConformerS_1QS_ ] ] = hidden constant [ 2 x i8 * ] [ <nl> + / / CHECK : i8 * bitcast ( [ 4 x i8 * ] * [ [ CONFORMER_P_WITNESS_TABLE : @ _TWPV18sil_witness_tables9ConformerS_1PS_ ] ] to i8 * ) , <nl> + / / CHECK : i8 * bitcast ( void ( % V18sil_witness_tables9Conformer * , % swift . type * ) * @ _TTWV18sil_witness_tables9ConformerS_1QS_FS1_7qMethoduRq_S1__fq_FT_T_ to i8 * ) <nl> + / / CHECK : ] <nl> + / / CHECK : [ [ CONFORMER_P_WITNESS_TABLE ] ] = hidden constant [ 4 x i8 * ] [ <nl> / / - - FIXME : associated type and witness table <nl> / / CHECK : i8 * null , <nl> / / CHECK : i8 * null , <nl> / / CHECK : i8 * bitcast ( void ( % swift . type * , % swift . type * ) * @ _TTWV18sil_witness_tables9ConformerS_1PS_ZFS1_12staticMethoduRq_S1__fMq_FT_T_ to i8 * ) , <nl> / / CHECK : i8 * bitcast ( void ( % V18sil_witness_tables9Conformer * , % swift . type * ) * @ _TTWV18sil_witness_tables9ConformerS_1PS_FS1_14instanceMethoduRq_S1__fq_FT_T_ to i8 * ) <nl> / / CHECK : ] <nl> - / / CHECK : [ [ CONFORMER_Q_WITNESS_TABLE : @ _TWPV18sil_witness_tables9ConformerS_1QS_ ] ] = hidden constant [ 2 x i8 * ] [ <nl> - / / CHECK : i8 * bitcast ( [ 4 x i8 * ] * [ [ CONFORMER_P_WITNESS_TABLE ] ] to i8 * ) , <nl> - / / CHECK : i8 * bitcast ( void ( % V18sil_witness_tables9Conformer * , % swift . type * ) * @ _TTWV18sil_witness_tables9ConformerS_1QS_FS1_7qMethoduRq_S1__fq_FT_T_ to i8 * ) <nl> - / / CHECK : ] <nl> / / CHECK : [ [ CONFORMER2_P_WITNESS_TABLE : @ _TWPV18sil_witness_tables10Conformer2S_1PS_ ] ] = hidden constant [ 4 x i8 * ] <nl> <nl> struct Conformer2 : Q { <nl> new file mode 100644 <nl> index 000000000000 . . b5705eb2e82a <nl> mmm / dev / null <nl> ppp b / test / SILGen / Inputs / inherited_protocol_conformance_other_file . swift <nl> <nl> + class B : P { } <nl> + protocol P { } <nl> + protocol Q : P { } <nl> + protocol R : Q { } <nl> new file mode 100644 <nl> index 000000000000 . . 5d29b7b887f9 <nl> mmm / dev / null <nl> ppp b / test / SILGen / inherited_protocol_conformance_multi_file . swift <nl> <nl> + / / RUN : % target - swift - frontend - emit - silgen - primary - file % s % S / Inputs / inherited_protocol_conformance_other_file . swift - module - name main | FileCheck % s - - check - prefix = THIS_FILE <nl> + / / RUN : % target - swift - frontend - emit - silgen % s - primary - file % S / Inputs / inherited_protocol_conformance_other_file . swift - module - name main | FileCheck % s - - check - prefix = OTHER_FILE <nl> + <nl> + / / THIS_FILE - NOT : sil_witness_table { { . * } } B : P <nl> + / / THIS_FILE - LABEL : sil_witness_table hidden D : R module main <nl> + / / THIS_FILE - NOT : sil_witness_table { { . * } } B : P <nl> + / / THIS_FILE - LABEL : sil_witness_table hidden D : Q module main <nl> + / / THIS_FILE - NOT : sil_witness_table { { . * } } B : P <nl> + <nl> + / / OTHER_FILE - LABEL : sil_witness_table hidden B : P module main <nl> + <nl> + class D : B , R { } <nl> mmm a / test / SILGen / witness_tables . swift <nl> ppp b / test / SILGen / witness_tables . swift <nl> struct InheritedConformance : InheritedProtocol1 { <nl> func inheritedMethod ( ) { } <nl> } <nl> func < ~ > ( x : InheritedConformance , y : InheritedConformance ) { } <nl> + / / TABLE - LABEL : sil_witness_table hidden InheritedConformance : InheritedProtocol1 module witness_tables { <nl> + / / TABLE - NEXT : base_protocol AnyProtocol : InheritedConformance : AnyProtocol module witness_tables <nl> + / / TABLE - NEXT : method # InheritedProtocol1 . inheritedMethod ! 1 : @ _TTWV14witness_tables20InheritedConformanceS_18InheritedProtocol1S_FS1_15inheritedMethoduRq_S1__fq_FT_T_ <nl> + / / TABLE - NEXT : } <nl> / / TABLE - LABEL : sil_witness_table hidden InheritedConformance : AnyProtocol module witness_tables { <nl> / / TABLE - NEXT : associated_type AssocType : SomeAssoc <nl> / / TABLE - NEXT : associated_type AssocWithReqt : ConformingAssoc <nl> func < ~ > ( x : InheritedConformance , y : InheritedConformance ) { } <nl> / / TABLE - NEXT : method # AnyProtocol . staticMethod ! 1 : @ _TTWV14witness_tables20InheritedConformanceS_11AnyProtocolS_ZFS1_12staticMethoduRq_S1__fMq_FT1xq__T_ <nl> / / TABLE - NEXT : method # AnyProtocol . " < ~ > " ! 1 : @ _TTWV14witness_tables20InheritedConformanceS_11AnyProtocolS_ZFS1_oi3ltguRq_S1__fMq_FTq_q__T_ <nl> / / TABLE - NEXT : } <nl> - / / TABLE - LABEL : sil_witness_table hidden InheritedConformance : InheritedProtocol1 module witness_tables { <nl> - / / TABLE - NEXT : base_protocol AnyProtocol : InheritedConformance : AnyProtocol module witness_tables <nl> - / / TABLE - NEXT : method # InheritedProtocol1 . inheritedMethod ! 1 : @ _TTWV14witness_tables20InheritedConformanceS_18InheritedProtocol1S_FS1_15inheritedMethoduRq_S1__fq_FT_T_ <nl> - / / TABLE - NEXT : } <nl> <nl> struct RedundantInheritedConformance : InheritedProtocol1 , AnyProtocol { <nl> typealias AssocType = SomeAssoc <nl> struct RedundantInheritedConformance : InheritedProtocol1 , AnyProtocol { <nl> func inheritedMethod ( ) { } <nl> } <nl> func < ~ > ( x : RedundantInheritedConformance , y : RedundantInheritedConformance ) { } <nl> + / / TABLE - LABEL : sil_witness_table hidden RedundantInheritedConformance : InheritedProtocol1 module witness_tables { <nl> + / / TABLE - NEXT : base_protocol AnyProtocol : RedundantInheritedConformance : AnyProtocol module witness_tables <nl> + / / TABLE - NEXT : method # InheritedProtocol1 . inheritedMethod ! 1 : @ _TTWV14witness_tables29RedundantInheritedConformanceS_18InheritedProtocol1S_FS1_15inheritedMethoduRq_S1__fq_FT_T_ <nl> + / / TABLE - NEXT : } <nl> / / TABLE - LABEL : sil_witness_table hidden RedundantInheritedConformance : AnyProtocol module witness_tables { <nl> / / TABLE - NEXT : associated_type AssocType : SomeAssoc <nl> / / TABLE - NEXT : associated_type AssocWithReqt : ConformingAssoc <nl> func < ~ > ( x : RedundantInheritedConformance , y : RedundantInheritedConformance ) { } <nl> / / TABLE - NEXT : method # AnyProtocol . staticMethod ! 1 : @ _TTWV14witness_tables29RedundantInheritedConformanceS_11AnyProtocolS_ZFS1_12staticMethoduRq_S1__fMq_FT1xq__T_ <nl> / / TABLE - NEXT : method # AnyProtocol . " < ~ > " ! 1 : @ _TTWV14witness_tables29RedundantInheritedConformanceS_11AnyProtocolS_ZFS1_oi3ltguRq_S1__fMq_FTq_q__T_ <nl> / / TABLE - NEXT : } <nl> - / / TABLE - LABEL : sil_witness_table hidden RedundantInheritedConformance : InheritedProtocol1 module witness_tables { <nl> - / / TABLE - NEXT : base_protocol AnyProtocol : RedundantInheritedConformance : AnyProtocol module witness_tables <nl> - / / TABLE - NEXT : method # InheritedProtocol1 . inheritedMethod ! 1 : @ _TTWV14witness_tables29RedundantInheritedConformanceS_18InheritedProtocol1S_FS1_15inheritedMethoduRq_S1__fq_FT_T_ <nl> - / / TABLE - NEXT : } <nl> <nl> struct DiamondInheritedConformance : InheritedProtocol1 , InheritedProtocol2 { <nl> typealias AssocType = SomeAssoc <nl> struct DiamondInheritedConformance : InheritedProtocol1 , InheritedProtocol2 { <nl> func inheritedMethod ( ) { } <nl> } <nl> func < ~ > ( x : DiamondInheritedConformance , y : DiamondInheritedConformance ) { } <nl> + / / TABLE - LABEL : sil_witness_table hidden DiamondInheritedConformance : InheritedProtocol1 module witness_tables { <nl> + / / TABLE - NEXT : base_protocol AnyProtocol : DiamondInheritedConformance : AnyProtocol module witness_tables <nl> + / / TABLE - NEXT : method # InheritedProtocol1 . inheritedMethod ! 1 : @ _TTWV14witness_tables27DiamondInheritedConformanceS_18InheritedProtocol1S_FS1_15inheritedMethoduRq_S1__fq_FT_T_ <nl> + / / TABLE - NEXT : } <nl> + / / TABLE - LABEL : sil_witness_table hidden DiamondInheritedConformance : InheritedProtocol2 module witness_tables { <nl> + / / TABLE - NEXT : base_protocol AnyProtocol : DiamondInheritedConformance : AnyProtocol module witness_tables <nl> + / / TABLE - NEXT : method # InheritedProtocol2 . inheritedMethod ! 1 : @ _TTWV14witness_tables27DiamondInheritedConformanceS_18InheritedProtocol2S_FS1_15inheritedMethoduRq_S1__fq_FT_T_ <nl> + / / TABLE - NEXT : } <nl> / / TABLE - LABEL : sil_witness_table hidden DiamondInheritedConformance : AnyProtocol module witness_tables { <nl> / / TABLE - NEXT : associated_type AssocType : SomeAssoc <nl> / / TABLE - NEXT : associated_type AssocWithReqt : ConformingAssoc <nl> func < ~ > ( x : DiamondInheritedConformance , y : DiamondInheritedConformance ) { } <nl> / / TABLE - NEXT : method # AnyProtocol . staticMethod ! 1 : @ _TTWV14witness_tables27DiamondInheritedConformanceS_11AnyProtocolS_ZFS1_12staticMethoduRq_S1__fMq_FT1xq__T_ <nl> / / TABLE - NEXT : method # AnyProtocol . " < ~ > " ! 1 : @ _TTWV14witness_tables27DiamondInheritedConformanceS_11AnyProtocolS_ZFS1_oi3ltguRq_S1__fMq_FTq_q__T_ <nl> / / TABLE - NEXT : } <nl> - / / TABLE - LABEL : sil_witness_table hidden DiamondInheritedConformance : InheritedProtocol1 module witness_tables { <nl> - / / TABLE - NEXT : base_protocol AnyProtocol : DiamondInheritedConformance : AnyProtocol module witness_tables <nl> - / / TABLE - NEXT : method # InheritedProtocol1 . inheritedMethod ! 1 : @ _TTWV14witness_tables27DiamondInheritedConformanceS_18InheritedProtocol1S_FS1_15inheritedMethoduRq_S1__fq_FT_T_ <nl> - / / TABLE - NEXT : } <nl> - / / TABLE - LABEL : sil_witness_table hidden DiamondInheritedConformance : InheritedProtocol2 module witness_tables { <nl> - / / TABLE - NEXT : base_protocol AnyProtocol : DiamondInheritedConformance : AnyProtocol module witness_tables <nl> - / / TABLE - NEXT : method # InheritedProtocol2 . inheritedMethod ! 1 : @ _TTWV14witness_tables27DiamondInheritedConformanceS_18InheritedProtocol2S_FS1_15inheritedMethoduRq_S1__fq_FT_T_ <nl> - / / TABLE - NEXT : } <nl> <nl> class ClassInheritedConformance : InheritedClassProtocol { <nl> typealias AssocType = SomeAssoc <nl> class ClassInheritedConformance : InheritedClassProtocol { <nl> func inheritedMethod ( ) { } <nl> } <nl> func < ~ > ( x : ClassInheritedConformance , y : ClassInheritedConformance ) { } <nl> + / / TABLE - LABEL : sil_witness_table hidden ClassInheritedConformance : InheritedClassProtocol module witness_tables { <nl> + / / TABLE - NEXT : base_protocol AnyProtocol : ClassInheritedConformance : AnyProtocol module witness_tables <nl> + / / TABLE - NEXT : method # InheritedClassProtocol . inheritedMethod ! 1 : @ _TTWC14witness_tables25ClassInheritedConformanceS_22InheritedClassProtocolS_FS1_15inheritedMethoduRq_S1__fq_FT_T_ <nl> + / / TABLE - NEXT : } <nl> / / TABLE - LABEL : sil_witness_table hidden ClassInheritedConformance : AnyProtocol module witness_tables { <nl> / / TABLE - NEXT : associated_type AssocType : SomeAssoc <nl> / / TABLE - NEXT : associated_type AssocWithReqt : ConformingAssoc <nl> func < ~ > ( x : ClassInheritedConformance , y : ClassInheritedConformance ) { } <nl> / / TABLE - NEXT : method # AnyProtocol . staticMethod ! 1 : @ _TTWC14witness_tables25ClassInheritedConformanceS_11AnyProtocolS_ZFS1_12staticMethoduRq_S1__fMq_FT1xq__T_ <nl> / / TABLE - NEXT : method # AnyProtocol . " < ~ > " ! 1 : @ _TTWC14witness_tables25ClassInheritedConformanceS_11AnyProtocolS_ZFS1_oi3ltguRq_S1__fMq_FTq_q__T_ <nl> / / TABLE - NEXT : } <nl> - / / TABLE - LABEL : sil_witness_table hidden ClassInheritedConformance : InheritedClassProtocol module witness_tables { <nl> - / / TABLE - NEXT : base_protocol AnyProtocol : ClassInheritedConformance : AnyProtocol module witness_tables <nl> - / / TABLE - NEXT : method # InheritedClassProtocol . inheritedMethod ! 1 : @ _TTWC14witness_tables25ClassInheritedConformanceS_22InheritedClassProtocolS_FS1_15inheritedMethoduRq_S1__fq_FT_T_ <nl> - / / TABLE - NEXT : } <nl> / / - - Witnesses have the ' self ' abstraction level of their protocol . <nl> / / AnyProtocol has no class bound , so its witnesses treat Self as opaque . <nl> / / InheritedClassProtocol has a class bound , so its witnesses treat Self as <nl> / / a reference value . <nl> - / / SYMBOL : sil hidden [ transparent ] [ thunk ] @ _TTWC14witness_tables25ClassInheritedConformanceS_11AnyProtocolS_FS1_6method { { . * } } : $ @ convention ( witness_method ) ( Arg , @ in ClassInheritedConformance , @ in_guaranteed ClassInheritedConformance ) - > ( ) <nl> / / SYMBOL : sil hidden [ transparent ] [ thunk ] @ _TTWC14witness_tables25ClassInheritedConformanceS_22InheritedClassProtocolS_FS1_15inheritedMethoduRq_S1__fq_FT_T_ : $ @ convention ( witness_method ) ( @ guaranteed ClassInheritedConformance ) - > ( ) <nl> + / / SYMBOL : sil hidden [ transparent ] [ thunk ] @ _TTWC14witness_tables25ClassInheritedConformanceS_11AnyProtocolS_FS1_6method { { . * } } : $ @ convention ( witness_method ) ( Arg , @ in ClassInheritedConformance , @ in_guaranteed ClassInheritedConformance ) - > ( ) <nl> <nl> struct GenericAssocType < T > : AssocReqt { <nl> func requiredMethod ( ) { } <nl> mmm a / test / SILGen / witnesses . swift <nl> ppp b / test / SILGen / witnesses . swift <nl> final class FailableClassModel : FailableClassRequirement , IUOFailableClassRequir <nl> } <nl> <nl> final class IUOFailableClassModel : NonFailableClassRefinement , IUOFailableClassRequirement { <nl> - / / CHECK - LABEL : sil hidden [ transparent ] [ thunk ] @ _TTWC9witnesses21IUOFailableClassModelS_24FailableClassRequirementS_FS1_CuRq_S1__fMq_FT3fooSi_GSqq__ <nl> - / / CHECK : select_enum_addr <nl> - / / CHECK : unchecked_take_enum_data_addr <nl> - / / CHECK : enum $ Optional { { . * } } Some <nl> - / / CHECK : enum $ Optional { { . * } } None <nl> - / / CHECK : return { { . * } } : $ Optional < IUOFailableClassModel > <nl> - <nl> / / CHECK - LABEL : sil hidden [ transparent ] [ thunk ] @ _TTWC9witnesses21IUOFailableClassModelS_26NonFailableClassRefinementS_FS1_CuRq_S1__fMq_FT3fooSi_q_ <nl> / / CHECK : function_ref @ _TFSs36_getImplicitlyUnwrappedOptionalValueurFGSQq__q_ <nl> / / CHECK : return [ [ RESULT : % [ 0 - 9 ] + ] ] : $ IUOFailableClassModel <nl> <nl> / / CHECK - LABEL : sil hidden [ transparent ] [ thunk ] @ _TTWC9witnesses21IUOFailableClassModelS_27IUOFailableClassRequirementS_FS1_CuRq_S1__fMq_FT3fooSi_GSQq__ <nl> init ! ( foo : Int ) { } <nl> + <nl> + / / CHECK - LABEL : sil hidden [ transparent ] [ thunk ] @ _TTWC9witnesses21IUOFailableClassModelS_24FailableClassRequirementS_FS1_CuRq_S1__fMq_FT3fooSi_GSqq__ <nl> + / / CHECK : select_enum_addr <nl> + / / CHECK : unchecked_take_enum_data_addr <nl> + / / CHECK : enum $ Optional { { . * } } Some <nl> + / / CHECK : enum $ Optional { { . * } } None <nl> + / / CHECK : return { { . * } } : $ Optional < IUOFailableClassModel > <nl> } <nl> <nl> protocol HasAssoc { <nl>
SILGen : No longer recursively emit inherited conformances .
apple/swift
abf953e5e80b9d90a74fe00da607d002ec872eb0
2015-05-28T01:05:37Z
mmm a / tensorflow / python / keras / losses . py <nl> ppp b / tensorflow / python / keras / losses . py <nl> def huber ( y_true , y_pred , delta = 1 . 0 ) : <nl> " " " <nl> y_pred = math_ops . cast ( y_pred , dtype = K . floatx ( ) ) <nl> y_true = math_ops . cast ( y_true , dtype = K . floatx ( ) ) <nl> + delta = math_ops . cast ( delta , dtype = K . floatx ( ) ) <nl> error = math_ops . subtract ( y_pred , y_true ) <nl> abs_error = math_ops . abs ( error ) <nl> quadratic = math_ops . minimum ( abs_error , delta ) <nl>
Fix Huber Loss crashes due to data type mismatch
tensorflow/tensorflow
edf5029353c452a5599dd02e95adee5657cd5599
2020-05-03T16:28:29Z
mmm a / third_party / cares / cares . BUILD <nl> ppp b / third_party / cares / cares . BUILD <nl> config_setting ( <nl> values = { " cpu " : " darwin " } , <nl> ) <nl> <nl> + config_setting ( <nl> + name = " darwin_x86_64 " , <nl> + values = { " cpu " : " darwin_x86_64 " } , <nl> + ) <nl> + <nl> config_setting ( <nl> name = " windows " , <nl> values = { " cpu " : " x64_windows " } , <nl> genrule ( <nl> " : ios_armv7s " : [ " @ com_github_grpc_grpc / / third_party / cares : config_darwin / ares_config . h " ] , <nl> " : ios_arm64 " : [ " @ com_github_grpc_grpc / / third_party / cares : config_darwin / ares_config . h " ] , <nl> " : darwin " : [ " @ com_github_grpc_grpc / / third_party / cares : config_darwin / ares_config . h " ] , <nl> + " : darwin_x86_64 " : [ " @ com_github_grpc_grpc / / third_party / cares : config_darwin / ares_config . h " ] , <nl> " : windows " : [ " @ com_github_grpc_grpc / / third_party / cares : config_windows / ares_config . h " ] , <nl> " : android " : [ " @ com_github_grpc_grpc / / third_party / cares : config_android / ares_config . h " ] , <nl> " / / conditions : default " : [ " @ com_github_grpc_grpc / / third_party / cares : config_linux / ares_config . h " ] , <nl>
Support " darwin_x86_64 " CPU in cares . BUILD .
grpc/grpc
330e0f3ba8770ffceb1b7e7d34d7cd7b6896c913
2019-02-21T17:52:17Z
mmm a / AirLib / include / physics / World . hpp <nl> ppp b / AirLib / include / physics / World . hpp <nl> class World : public UpdatableContainer < UpdatableObject * > { <nl> UpdatableContainer : : clear ( ) ; <nl> } <nl> <nl> - virtual void insert ( UpdatableObject * member ) <nl> + virtual void insert ( UpdatableObject * member ) override <nl> { <nl> if ( physics_engine_ & & member - > getPhysicsBody ( ) ! = nullptr ) <nl> physics_engine_ - > insert ( static_cast < PhysicsBody * > ( member - > getPhysicsBody ( ) ) ) ; <nl> class World : public UpdatableContainer < UpdatableObject * > { <nl> UpdatableContainer : : insert ( member ) ; <nl> } <nl> <nl> - virtual void erase_remove ( UpdatableObject * member ) <nl> + virtual void erase_remove ( UpdatableObject * member ) override <nl> { <nl> if ( physics_engine_ & & member - > getPhysicsBody ( ) ! = nullptr ) <nl> physics_engine_ - > erase_remove ( static_cast < PhysicsBody * > ( member ) ) ; <nl>
Fixed warnings
microsoft/AirSim
6a4f3fbcbb6bbeed25652e2c30b1b3ee58d1ee72
2017-08-14T04:43:45Z